elegance-js 1.1.4 → 1.2.1

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.
@@ -1061,7 +1061,7 @@ var compile = async (props) => {
1061
1061
  };
1062
1062
 
1063
1063
  // src/compile_docs.ts
1064
- import { execSync } from "child_process";
1064
+ import { exec, execSync } from "child_process";
1065
1065
  import path2 from "path";
1066
1066
  var __dirname2 = path2.dirname(fileURLToPath2(import.meta.url));
1067
1067
  var PAGES_DIR = path2.join(__dirname2, "../src/docs");
@@ -1078,11 +1078,14 @@ compile({
1078
1078
  publicDirectory: {
1079
1079
  path: PUBLIC_DIR,
1080
1080
  method: environment === "production" ? "recursive-copy" : "symlink"
1081
+ },
1082
+ server: {
1083
+ runServer: environment === "development"
1081
1084
  }
1082
1085
  }).then(() => {
1083
1086
  if (environment === "production") {
1084
1087
  execSync(`npx @tailwindcss/cli -i ${PAGES_DIR}/index.css -o ${OUTPUT_DIR}/dist/index.css --minify`);
1085
1088
  } else {
1086
- execSync(`npx @tailwindcss/cli -i ${PAGES_DIR}/index.css -o ${OUTPUT_DIR}/dist/index.css --watch=always`);
1089
+ exec(`npx @tailwindcss/cli -i ${PAGES_DIR}/index.css -o ${OUTPUT_DIR}/dist/index.css --watch=always`);
1087
1090
  }
1088
1091
  });
@@ -668,18 +668,7 @@ var Mono = (text) => span({
668
668
  class: "font-mono select-text"
669
669
  }, text);
670
670
 
671
- // src/docs/docs/components/Subtext.ts
672
- var Subtext = (text) => span({
673
- class: "text-xs opacity-60",
674
- innerText: text
675
- });
676
-
677
671
  // src/docs/docs/basics/page.ts
678
- var demoPageTS = `export const page = body ({
679
- style: "background-color: #000; color: #fff;",
680
- },
681
- h1 ("Greetings Traveler!"),
682
- );`;
683
672
  var bodyCallResult = `
684
673
  {
685
674
  tag: "body",
@@ -697,19 +686,15 @@ var bodyCallResult = `
697
686
  ],
698
687
  }
699
688
  `;
689
+ var demoPageTS = `export const page = body ({
690
+ style: "background-color: #000; color: #fff;",
691
+ },
692
+ h1 ("Greetings Traveler!"),
693
+ );`;
700
694
  var demoInfoTS = `export const metadata = () => head (
701
695
  title ("The BEST Page Ever!"),
702
696
  );
703
697
  `;
704
- var demoIndexTs = `import { compile } from "elegance-js/build";
705
-
706
- compile({
707
- environment: "development",
708
- outputDirectory: "./.elegance",
709
- pagesDirectory: "./pages",
710
- writeToHTML: true,
711
- });`;
712
- var demoFirstPage = `export const page = body ("Greetings Traveller!");`;
713
698
  var metadata = () => head(
714
699
  {},
715
700
  link({
@@ -732,7 +717,7 @@ var page = RootLayout(
732
717
  {
733
718
  class: "opacity-80"
734
719
  },
735
- "Elegance is still in very early development.",
720
+ "Elegance is still only in Beta.",
736
721
  br(),
737
722
  "There are absolutely no guarantees of backwards compatibility, security or really anything.",
738
723
  br(),
@@ -882,6 +867,11 @@ var page = RootLayout(
882
867
  Mono("compile()"),
883
868
  " which your project should call to build itself.",
884
869
  br(),
870
+ "This is typically done via the use of the built in build scripts.",
871
+ br(),
872
+ "However, if you wish to customize your build options, you need just create a file which calls compile.",
873
+ br(),
874
+ br(),
885
875
  "Compilation handles generating page_data files, ",
886
876
  "HTML, JSON, transpilation of ts into js, etc.",
887
877
  br(),
@@ -897,274 +887,105 @@ var page = RootLayout(
897
887
  ),
898
888
  h3({
899
889
  class: "text-lg font-medium mb-1",
900
- innerText: "GitHub"
890
+ innerText: "NPM"
901
891
  }),
902
892
  p(
903
893
  {
904
894
  class: "opacity-80"
905
895
  },
906
- "As Elegance is still in it's formative stages, ",
907
- "we haven't yet published to things like the NPM registry.",
896
+ "To make an elegance project, first create a directory with a name of your choosing.",
908
897
  br(),
909
- "However, installation is still quite simple.",
898
+ "For this example, we'll use ",
899
+ Mono("my-first-webpage"),
910
900
  br(),
911
- br(),
912
- "First, decide where you'll want Elegance to live. ",
913
- br(),
914
- "On a linux-based system, somewhere like ",
915
- Mono("~/bin/elegance"),
916
- " is a good place.",
917
- br(),
918
- b("Just remember where it is! You'll need it later."),
919
- br(),
920
- br(),
921
- "Install ",
922
- a({
923
- href: "https://git-scm.com/",
924
- class: "border-b-2 border-text-50"
925
- }, "git"),
926
- " for your system, if you haven't already.",
927
- br(),
928
- br(),
929
- "Next, open a terminal / command prompt window, and issue the following the command."
930
- ),
931
- CodeBlock("git clone https://github.com/valdemar-dev/elegance-js [your destination folder]", false),
932
- p(
933
- {
934
- class: "opacity-80"
935
- },
936
- "You have now installed Elegance.JS onto your system. Congratulations!"
937
- ),
938
- Separator(),
939
- PageHeading(
940
- "Your First Page",
941
- "your-first-page"
901
+ "Then, in that directory, issue the following command to initialize an empty NPM project."
942
902
  ),
943
- h3({
944
- class: "text-lg font-medium mb-1",
945
- innerText: "Making a Project"
946
- }),
903
+ CodeBlock("npm init -y", false),
947
904
  p(
948
905
  {
949
906
  class: "opacity-80"
950
907
  },
951
- "Now that Elegance is installed on your machine, it's time to make your first page.",
952
- br(),
953
- "With your terminal still open, go ahead and make a new a directory where your project will live.",
954
- br(),
955
- br(),
956
- "Once that's done, navigate to the directory you just made, and run this command."
908
+ "After this, install elegance-js by running"
957
909
  ),
958
- CodeBlock("npm init -y && npm install esbuild", false),
910
+ CodeBlock("npm install elegance-js", false),
959
911
  p(
960
912
  {
961
913
  class: "opacity-80"
962
914
  },
963
- "This will initialize npm, and install ",
964
- b("esbuild"),
965
- ", Elegances only dependency.",
966
- br(),
967
- br(),
968
- "For the unitiated, esbuild is a ridiculously fast JS bundler written in Go."
915
+ "And that's it! Elegance.js has been installed into your project."
969
916
  ),
970
- p(
971
- {
972
- class: "opacity-80"
973
- },
974
- "Next, you'll need to link Elegance to your project."
917
+ Separator(),
918
+ PageHeading(
919
+ "Your First Page",
920
+ "your-first-page"
975
921
  ),
976
- CodeBlock("npm link [where you installed elegance]", false),
977
- Subtext("(you might need sudo for this if you're on linux)"),
978
- div({
979
- class: "my-10"
980
- }),
981
922
  h3({
982
923
  class: "text-lg font-medium mb-1",
983
- innerText: "Typescript Configuration"
924
+ innerText: "Making a Project"
984
925
  }),
985
926
  p(
986
927
  {
987
928
  class: "opacity-80"
988
929
  },
989
- "Now, for the TypeScript users, you'll want to do these next few steps.",
990
- br(),
991
- "First, boostrap a ",
992
- Mono("tsconfig.json"),
993
- " so typescript works properly.",
994
- "Set the compiler target to ",
995
- Mono("esnext"),
996
- " and module to ",
997
- Mono("esnext"),
998
- br(),
999
- Subtext("Note: You might need to set your moduleResolution as bundler, or this might not work."),
1000
- br(),
1001
- br(),
1002
- "Create a file at the root of your project called ",
1003
- Mono("env.d.ts"),
1004
- br(),
1005
- "And put this inside of it."
1006
- ),
1007
- CodeBlock('/// <reference path="elegance-js/global" />', false),
1008
- p(
1009
- {
1010
- class: "opacity-80"
1011
- },
1012
- "This takes the ambient global types from Elegance, and puts them into your project.",
1013
- br(),
1014
- "If all goes well, Elegance should be setup fully now!"
930
+ "To bootstrap an Elegance.js project, run the following command in the directory we just made."
1015
931
  ),
1016
- div({
1017
- class: "my-10"
1018
- }),
1019
- h3({
1020
- class: "text-lg font-medium mb-1",
1021
- innerText: "Creating Pages"
1022
- }),
932
+ CodeBlock("npx bootstrap", false),
1023
933
  p(
1024
934
  {
1025
935
  class: "opacity-80"
1026
936
  },
1027
- "Like we mentioned earlier, a page requires just one file. ",
1028
- Mono("page.ts"),
937
+ "This will create a few files and directories for you.",
1029
938
  br(),
1030
- "So, let's create that, shall we?",
1031
- br(),
1032
- br(),
1033
- "At the root of your project, create a directory. You can call it pages, app, whatever you want.",
1034
- br(),
1035
- br(),
1036
- "In this new directory, create a ",
939
+ "Firstly, it creates the aforementioned pages directory, and an example ",
1037
940
  Mono("page.ts"),
1038
941
  " file.",
1039
942
  br(),
1040
- "Just for a start, put something simple into it. Like this.",
1041
- br(),
1042
- "We'll get whacky and crazy later on, don't worry."
1043
- ),
1044
- CodeBlock(demoFirstPage),
1045
- CodeBlock(demoInfoTS),
1046
- div({
1047
- class: "my-10"
1048
- }),
1049
- h3({
1050
- class: "text-lg font-medium mb-1",
1051
- innerText: "Building your Project"
1052
- }),
1053
- p(
1054
- {
1055
- class: "opacity-80"
1056
- },
1057
- "Create an ",
1058
- Mono("index.ts"),
1059
- " file at the root of your project.",
1060
- br(),
1061
- br(),
1062
- "Elegance exposes the ",
1063
- Mono("compile()"),
1064
- " function from it's build process,",
1065
- br(),
1066
- "which we'll be using to compile your project."
1067
- ),
1068
- CodeBlock(demoIndexTs),
1069
- p(
1070
- {
1071
- class: "opacity-80"
1072
- },
1073
- "Here's an example usage of the ",
1074
- Mono("compile()"),
1075
- " function.",
1076
- br(),
1077
- br(),
1078
- Mono('environment: "development"'),
1079
- br(),
1080
- " Means that Elegance won't minify your page code, and will create a 'watch-server',",
1081
- br(),
1082
- "which will auto-reload your pages when you save them.",
1083
- br(),
1084
943
  br(),
1085
- Mono('outputDirectory: "./.elegance"'),
944
+ "Then it makes a public directory where you can store files",
1086
945
  br(),
1087
- " This is where Elegance will put it's compiled files into.,",
946
+ "that you want to be publicly accessible on your website.",
1088
947
  br(),
1089
- "We wouldn't recommend changing this, however, you can, if need be.",
1090
948
  br(),
949
+ "Thirdly, it creates an ",
950
+ Mono("env.d.ts + tsconfig.json"),
1091
951
  br(),
1092
- Mono('pagesDirectory: "./pages"'),
952
+ "which gives you ambient global typings for the elements that are in Elegance.",
1093
953
  br(),
1094
- "This is the directory where you put your pages.",
1095
954
  br(),
1096
- "You should make it match whatever you named the directory obviously.",
955
+ "Lastly, it creates a file in the pages directory called ",
956
+ Mono("index.css"),
1097
957
  br(),
1098
- br(),
1099
- Mono("writeToHTML: true"),
1100
- br(),
1101
- "This makes Elegance write static HTML files, instead of keeping the generated page JSON",
1102
- br(),
1103
- "You can turn this off if you want to server render per-request.",
1104
- br(),
1105
- br(),
1106
- ""
958
+ "which tailwind will automatically compile and put in your dist folder."
1107
959
  ),
1108
960
  div({
1109
961
  class: "my-10"
1110
- }),
962
+ }, []),
1111
963
  h3({
1112
964
  class: "text-lg font-medium mb-1",
1113
- innerText: "Running your Project"
965
+ innerText: "Running your project."
1114
966
  }),
1115
967
  p(
1116
968
  {
1117
969
  class: "opacity-80"
1118
970
  },
1119
- "You can choose how to run your own project. ",
1120
- br(),
1121
- "Elegance ",
1122
- i("should "),
1123
- "work with most JS runtimes like Node, Deno, etc.",
971
+ "There's a few way to run elegance.",
1124
972
  br(),
1125
- "However some (like Deno), may require a little tweaking.",
1126
973
  br(),
1127
- br(),
1128
- Link(
1129
- {
1130
- href: "/docs/running",
1131
- class: "border-b-2"
1132
- },
1133
- "More about running here."
1134
- )
1135
- ),
1136
- div({
1137
- class: "my-10"
1138
- }),
1139
- p(
1140
- {
1141
- class: "opacity-80"
1142
- },
1143
- "For the purposes of this tutorial, we'll try to keep it simple.",
1144
- br(),
1145
- "Simply issue the following commands in your terminal."
974
+ "The intended way is using our provided scripts."
1146
975
  ),
1147
- CodeBlock("npx tsx index.ts", false),
1148
- CodeBlock("python3 -m http.server 3000 -d .elegance", false),
976
+ CodeBlock("npx dev", false),
977
+ CodeBlock("npx prod", false),
978
+ CodeBlock("npx static", false),
1149
979
  p(
1150
980
  {
1151
981
  class: "opacity-80"
1152
982
  },
1153
- "This'll take your ",
1154
- Mono("index.ts"),
1155
- " run it, and then serve the ",
983
+ "However, you may also serve the files in any way you like.",
1156
984
  br(),
1157
- "generated files over a simple Python HTTP server.",
1158
985
  br(),
986
+ "API Routes will not be available without the built-in Elegance server,",
1159
987
  br(),
1160
- "And that's it! You can view your shiny new webpage at the URL, ",
1161
- a(
1162
- {
1163
- href: "http://localhost:3000/",
1164
- class: "border-b-2"
1165
- },
1166
- "localhost:3000."
1167
- )
988
+ "but all static content like event listeners, load hooks, pages, etc, will work."
1168
989
  )
1169
990
  )
1170
991
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "elegance-js",
3
- "version": "1.1.4",
3
+ "version": "1.2.1",
4
4
  "description": "Web-Framework",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,26 +18,86 @@ const envDtsPath = "env.d.ts";
18
18
  const tsconfigPath = "tsconfig.json";
19
19
 
20
20
  const pageTsContent = `
21
- export const page = body({
22
- class: "bg-black text-white flex items-center justify-center p-48",
21
+ import { createEventListener, createState } from "elegance-js/server/createState";
22
+ import { createLoadHook } from "elegance-js/server/loadHook";
23
+ import { observe } from "elegance-js/server/observe";
24
+
25
+ const counter = createState(0);
26
+
27
+ createLoadHook({
28
+ deps: [counter],
29
+ fn: (_, counter) => {
30
+ const interval = setInterval(() => {
31
+ counter.value++;
32
+ counter.signal();
33
+ }, 1000);
34
+
35
+ return () => clearInterval(interval);
36
+ },
37
+ })
38
+
39
+ export const page = body ({
40
+ class: "text-white flex min-h-screen items-start sm:justify-center p-4 bg-black flex-col gap-4 max-w-[500px] w-full mx-auto",
23
41
  },
24
- h1({
25
- class: "text-4xl",
42
+ h1 ({
43
+ class: "text-4xl font-inter font-semibold bg-clip-text text-transparent bg-gradient-to-tl from-[#EEB844] to-[#FF4FED] oveflow-clip",
26
44
  },
27
45
  "Welcome to Elegance.JS!",
28
46
  ),
47
+
48
+ p ({
49
+ },
50
+ "Edit page.ts to get started.",
51
+ ),
52
+
53
+ div({
54
+ class: "flex items-start gap-4 mt-2",
55
+ },
56
+ a ({
57
+ class: "px-4 py-2 rounded-md bg-red-400 text-black font-semibold relative group hover:scale-[1.05] duration-200",
58
+ href: "https://elegance.js.org/",
59
+ target: "_blank",
60
+ },
61
+ "Documentation",
62
+
63
+ div ({
64
+ class: "blur-[50px] absolute group-hover:bg-red-400 inset-0 bg-transparent duration-200 pointer-events-none -z-10",
65
+ "aria-hidden": "true",
66
+ }),
67
+ ),
68
+
69
+ button ({
70
+ class: "hover:cursor-pointer px-4 py-2 rounded-md bg-zinc-200 text-black font-semibold relative group hover:scale-[1.05] duration-200",
71
+ onClick: createEventListener({
72
+ dependencies: [counter],
73
+ eventListener: (_, counter) => {
74
+ counter.value++;
75
+
76
+ counter.signal();
77
+ },
78
+ }),
79
+
80
+ innerText: observe([counter], (counter) => \`Counter: ${counter}\`),
81
+ },
82
+ div ({
83
+ class: "blur-[50px] absolute group-hover:bg-zinc-200 inset-0 bg-transparent duration-200 pointer-events-none -z-10",
84
+ "aria-hidden": "true",
85
+ }),
86
+ ),
87
+ )
29
88
  );
30
89
 
31
- export const metadata = () => head({},
32
- link({
90
+ export const metadata = () => head ({},
91
+ link ({
33
92
  rel: "stylesheet",
34
93
  href: "/index.css",
35
94
  }),
36
95
 
37
- title({},
38
- "Hello World!"
96
+ title ({},
97
+ "Elegance.JS"
39
98
  ),
40
99
  )
100
+
41
101
  `;
42
102
 
43
103
  const envDtsContent = `/// <reference types="elegance-js/global" />`;
@@ -56,8 +116,22 @@ const tsconfigContent = JSON.stringify({
56
116
  exclude: ["node_modules"],
57
117
  }, null, 2);
58
118
 
119
+ const indexCssContent = `
120
+ @import url('https://fonts.googleapis.com/css2?family=Inter:ital,opsz,wght@0,14..32,100..900;1,14..32,100..900&display=swap');
121
+
122
+ * {
123
+ line-height: normal;
124
+ }
125
+
126
+ @import "tailwindcss";
127
+
128
+ @theme {
129
+ --font-inter: "Inter", sans-serif;
130
+ }
131
+ `;
132
+
59
133
  fs.writeFileSync(pageTsPath, pageTsContent, "utf8");
60
- fs.writeFileSync(indexCssPath, "", "utf8");
134
+ fs.writeFileSync(indexCssPath, indexCssContent, "utf8");
61
135
  fs.writeFileSync(envDtsPath, envDtsContent, "utf8");
62
136
  fs.writeFileSync(tsconfigPath, tsconfigContent, "utf8");
63
137