@thyn/core 0.0.343 → 0.0.346

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 (105) hide show
  1. package/.github/workflows/static.yml +48 -0
  2. package/.github/workflows/test.yml +39 -0
  3. package/LICENSE +21 -0
  4. package/README.md +50 -0
  5. package/dist/{element.js → core/element.js} +14 -36
  6. package/dist/core/index.d.ts +1 -0
  7. package/dist/core/index.js +1 -0
  8. package/dist/index.d.ts +5 -2
  9. package/dist/index.js +5 -2
  10. package/dist/plugin/html-parser.d.ts +31 -0
  11. package/dist/plugin/html-parser.js +275 -0
  12. package/dist/plugin/index.d.ts +24 -0
  13. package/dist/plugin/index.js +1009 -0
  14. package/dist/plugin/utils.d.ts +12 -0
  15. package/dist/plugin/utils.js +194 -0
  16. package/docs/CNAME +1 -0
  17. package/docs/index.html +18 -0
  18. package/docs/package-lock.json +980 -0
  19. package/docs/package.json +15 -0
  20. package/docs/public/thyn.png +0 -0
  21. package/docs/public/thyn.svg +1 -0
  22. package/docs/src/App.thyn +10 -0
  23. package/docs/src/components/Button.thyn +3 -0
  24. package/docs/src/docs/GettingStarted.thyn +8 -0
  25. package/docs/src/main.css +17 -0
  26. package/docs/src/main.js +5 -0
  27. package/docs/src/pages/Home.thyn +147 -0
  28. package/docs/vite.config.js +7 -0
  29. package/package.json +18 -10
  30. package/src/{element.ts → core/element.ts} +14 -34
  31. package/src/core/index.ts +1 -0
  32. package/src/{signals.ts → core/signals.ts} +1 -1
  33. package/src/index.ts +5 -15
  34. package/src/plugin/html-parser.ts +332 -0
  35. package/src/plugin/index.ts +1127 -0
  36. package/src/plugin/utils.ts +213 -0
  37. package/tests/Bind.test.ts +14 -0
  38. package/tests/Bind.thyn +7 -0
  39. package/tests/ConsecInterps.test.ts +9 -0
  40. package/tests/ConsecInterps.thyn +9 -0
  41. package/tests/Counter.test.ts +12 -0
  42. package/tests/Counter.thyn +7 -0
  43. package/tests/DoubleQuotes.test.ts +9 -0
  44. package/tests/DoubleQuotes.thyn +3 -0
  45. package/tests/Escape.test.ts +9 -0
  46. package/tests/Escape.thyn +3 -0
  47. package/tests/EscapeDollar.test.ts +9 -0
  48. package/tests/EscapeDollar.thyn +5 -0
  49. package/tests/EventPipes.test.ts +13 -0
  50. package/tests/EventPipes.thyn +11 -0
  51. package/tests/List.test.ts +21 -0
  52. package/tests/List.thyn +15 -0
  53. package/tests/ListV2.test.ts +20 -0
  54. package/tests/ListV2.thyn +16 -0
  55. package/tests/MixElemAndText.test.ts +9 -0
  56. package/tests/MixElemAndText.thyn +12 -0
  57. package/tests/Show.test.ts +13 -0
  58. package/tests/Show.thyn +8 -0
  59. package/tests/Template.test.ts +9 -0
  60. package/tests/Template.thyn +8 -0
  61. package/tests/list/comprehensive.test.ts +659 -0
  62. package/tests/list/operations/ChildrenAppend.thyn +11 -0
  63. package/tests/list/operations/ChildrenFilter.thyn +11 -0
  64. package/tests/list/operations/ChildrenInsert.thyn +11 -0
  65. package/tests/list/operations/ChildrenNoneToSome.thyn +11 -0
  66. package/tests/list/operations/ChildrenPrepend.thyn +11 -0
  67. package/tests/list/operations/ChildrenRemove.thyn +11 -0
  68. package/tests/list/operations/ChildrenReplaceAll.thyn +11 -0
  69. package/tests/list/operations/ChildrenSomeToNone.thyn +11 -0
  70. package/tests/list/operations/ChildrenSort.thyn +11 -0
  71. package/tests/list/operations/IsolatedAppend.thyn +10 -0
  72. package/tests/list/operations/IsolatedFilter.thyn +16 -0
  73. package/tests/list/operations/IsolatedInsert.thyn +10 -0
  74. package/tests/list/operations/IsolatedMove.thyn +16 -0
  75. package/tests/list/operations/IsolatedNoneToSome.thyn +16 -0
  76. package/tests/list/operations/IsolatedPrepend.thyn +10 -0
  77. package/tests/list/operations/IsolatedRemove.thyn +17 -0
  78. package/tests/list/operations/IsolatedReplaceAll.thyn +10 -0
  79. package/tests/list/operations/IsolatedSomeToNone.thyn +10 -0
  80. package/tests/list/operations/IsolatedSort.thyn +16 -0
  81. package/tests/list/operations/TerminalAppend.thyn +12 -0
  82. package/tests/list/operations/TerminalFilter.thyn +12 -0
  83. package/tests/list/operations/TerminalInsert.thyn +12 -0
  84. package/tests/list/operations/TerminalNoneToSome.thyn +12 -0
  85. package/tests/list/operations/TerminalPrepend.thyn +12 -0
  86. package/tests/list/operations/TerminalRemove.thyn +12 -0
  87. package/tests/list/operations/TerminalReplaceAll.thyn +12 -0
  88. package/tests/list/operations/TerminalSomeToNone.thyn +12 -0
  89. package/tests/list/operations/TerminalSort.thyn +12 -0
  90. package/tests/tsconfig.json +14 -0
  91. package/tsconfig.json +11 -6
  92. package/types/thyn.d.ts +4 -0
  93. package/vitest.config.ts +7 -2
  94. package/tests/fx.test.ts +0 -31
  95. package/tests/lists.test.ts +0 -184
  96. package/tests/router.test.ts +0 -69
  97. package/tests/show.test.ts +0 -66
  98. package/tests/utils.ts +0 -3
  99. package/tsconfig.tsbuildinfo +0 -1
  100. /package/dist/{element.d.ts → core/element.d.ts} +0 -0
  101. /package/dist/{router.d.ts → core/router.d.ts} +0 -0
  102. /package/dist/{router.js → core/router.js} +0 -0
  103. /package/dist/{signals.d.ts → core/signals.d.ts} +0 -0
  104. /package/dist/{signals.js → core/signals.js} +0 -0
  105. /package/src/{router.ts → core/router.ts} +0 -0
@@ -0,0 +1,12 @@
1
+ export declare function extractParts(code: string): {
2
+ script: string;
3
+ scriptLang: string;
4
+ style: string;
5
+ html: string;
6
+ };
7
+ export declare function escapeTemplateLiteral(text: string): string;
8
+ export declare function escapeHtml(text: string): string;
9
+ export declare function splitScript(script: string): {
10
+ imports: any[];
11
+ body: any[];
12
+ };
@@ -0,0 +1,194 @@
1
+ export function extractParts(code) {
2
+ const scriptMatch = code.match(/<script([^>]*?)>([\s\S]*?)<\/script>/);
3
+ const styleMatch = code.match(/<style[^>]*>([\s\S]*?)<\/style>/);
4
+ const html = code
5
+ .replace(/<script[^>]*>[\s\S]*?<\/script>/, "")
6
+ .replace(/<style[^>]*>[\s\S]*?<\/style>/, "")
7
+ .trim();
8
+ let scriptLang = "js";
9
+ if (scriptMatch && scriptMatch[1]) {
10
+ const langMatch = scriptMatch[1].match(/lang\s*=\s*["']([^"']+)["']/);
11
+ if (langMatch) {
12
+ scriptLang = langMatch[1];
13
+ }
14
+ }
15
+ return {
16
+ script: scriptMatch?.[2]?.trim() ?? "",
17
+ scriptLang,
18
+ style: styleMatch?.[1]?.trim() ?? "",
19
+ html,
20
+ };
21
+ }
22
+ ;
23
+ export function escapeTemplateLiteral(text) {
24
+ return text
25
+ .replace(/\\/g, '\\\\') // Escape backslashes
26
+ .replace(/`/g, '\\`') // Escape backticks
27
+ .replace(/\$/g, '\\$'); // Escape interpolation
28
+ }
29
+ export function escapeHtml(text) {
30
+ return text
31
+ .replace(/&/g, "&amp;")
32
+ .replace(/</g, "&lt;")
33
+ .replace(/>/g, "&gt;")
34
+ .replace(/"/g, "&quot;")
35
+ .replace(/'/g, "&#039;");
36
+ }
37
+ export function splitScript(script) {
38
+ if (!script || typeof script !== "string") {
39
+ return { imports: [], body: [] };
40
+ }
41
+ const lines = script.split("\n");
42
+ const imports = [];
43
+ const body = [];
44
+ let currentImport = [];
45
+ let inImport = false;
46
+ let braceCount = 0;
47
+ let inString = false;
48
+ let stringChar = "";
49
+ let inMultiLineComment = false;
50
+ // Helper function to check if import is complete without semicolon
51
+ function isImportComplete(line, braceCount, inString) {
52
+ // If we have balanced braces and not in a string, check if next non-empty line starts a new statement
53
+ if (braceCount === 0 && !inString) {
54
+ // Look ahead to see if next line starts a new statement/declaration
55
+ const nextLineIndex = lines.indexOf(line) + 1;
56
+ for (let i = nextLineIndex; i < lines.length; i++) {
57
+ const nextLine = lines[i].trim();
58
+ if (!nextLine || nextLine.startsWith("//") || nextLine.startsWith("/*")) {
59
+ continue; // Skip empty lines and comments
60
+ }
61
+ // If next line starts with typical JS keywords/patterns, current import is complete
62
+ return /^(const|let|var|function|class|export|if|for|while|switch|try|return|\w+\s*[=:]|\w+\()/
63
+ .test(nextLine);
64
+ }
65
+ // If we reached end of file, import is complete
66
+ return true;
67
+ }
68
+ return false;
69
+ }
70
+ for (let i = 0; i < lines.length; i++) {
71
+ const line = lines[i];
72
+ const trimmed = line.trim();
73
+ // Handle multi-line comments
74
+ if (inMultiLineComment) {
75
+ if (inImport) {
76
+ currentImport.push(line);
77
+ }
78
+ else {
79
+ body.push(line);
80
+ }
81
+ if (line.includes("*/")) {
82
+ inMultiLineComment = false;
83
+ }
84
+ continue;
85
+ }
86
+ // Check for start of multi-line comment
87
+ if (line.includes("/*") && !inString) {
88
+ inMultiLineComment = true;
89
+ if (inImport) {
90
+ currentImport.push(line);
91
+ }
92
+ else {
93
+ body.push(line);
94
+ }
95
+ if (!line.includes("*/")) {
96
+ continue;
97
+ }
98
+ else {
99
+ inMultiLineComment = false;
100
+ }
101
+ }
102
+ // Skip single-line comments when not in import
103
+ if (trimmed.startsWith("//") && !inImport) {
104
+ body.push(line);
105
+ continue;
106
+ }
107
+ // Skip empty lines when not in import
108
+ if (!trimmed && !inImport) {
109
+ body.push(line);
110
+ continue;
111
+ }
112
+ // Start of import statement
113
+ if (!inImport && trimmed.startsWith("import")) {
114
+ inImport = true;
115
+ currentImport = [line];
116
+ braceCount = 0;
117
+ inString = false;
118
+ // Count braces and track strings in the import line
119
+ for (let j = 0; j < line.length; j++) {
120
+ const char = line[j];
121
+ if (inString) {
122
+ if (char === stringChar && line[j - 1] !== "\\") {
123
+ inString = false;
124
+ stringChar = "";
125
+ }
126
+ }
127
+ else {
128
+ if (char === '"' || char === "'" || char === "`") {
129
+ inString = true;
130
+ stringChar = char;
131
+ }
132
+ else if (char === "{") {
133
+ braceCount++;
134
+ }
135
+ else if (char === "}") {
136
+ braceCount--;
137
+ }
138
+ }
139
+ }
140
+ // Check if import is complete
141
+ if ((trimmed.endsWith(";") ||
142
+ isImportComplete(trimmed, braceCount, inString)) &&
143
+ braceCount === 0 && !inString) {
144
+ imports.push(currentImport.join("\n"));
145
+ currentImport = [];
146
+ inImport = false;
147
+ }
148
+ } // Continue import statement
149
+ else if (inImport) {
150
+ currentImport.push(line);
151
+ // Count braces and track strings in the current line
152
+ for (let j = 0; j < line.length; j++) {
153
+ const char = line[j];
154
+ if (inString) {
155
+ if (char === stringChar && line[j - 1] !== "\\") {
156
+ inString = false;
157
+ stringChar = "";
158
+ }
159
+ }
160
+ else {
161
+ if (char === '"' || char === "'" || char === "`") {
162
+ inString = true;
163
+ stringChar = char;
164
+ }
165
+ else if (char === "{") {
166
+ braceCount++;
167
+ }
168
+ else if (char === "}") {
169
+ braceCount--;
170
+ }
171
+ }
172
+ }
173
+ // Check if import is complete
174
+ if ((trimmed.endsWith(";") ||
175
+ isImportComplete(trimmed, braceCount, inString)) &&
176
+ braceCount === 0 && !inString) {
177
+ imports.push(currentImport.join("\n"));
178
+ currentImport = [];
179
+ inImport = false;
180
+ }
181
+ } // Regular body content
182
+ else {
183
+ body.push(line);
184
+ }
185
+ }
186
+ // Handle unterminated import (likely malformed)
187
+ if (currentImport.length > 0) {
188
+ imports.push(currentImport.join("\n"));
189
+ }
190
+ return {
191
+ imports: imports.filter((imp) => imp.trim()),
192
+ body: body.length > 0 ? body : [""],
193
+ };
194
+ }
package/docs/CNAME ADDED
@@ -0,0 +1 @@
1
+ thyn.dev
@@ -0,0 +1,18 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+
4
+ <head>
5
+ <meta charset="UTF-8" />
6
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
+ <title>thyn</title>
8
+ <link rel="icon" type="image/svg" href="/thyn.svg">
9
+ <script type="module" src="/src/main.js"></script>
10
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/components/prism-core.min.js"></script>
11
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/plugins/autoloader/prism-autoloader.min.js"></script>
12
+ <link href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.29.0/themes/prism-tomorrow.min.css" rel="stylesheet" />
13
+ </head>
14
+
15
+ <body>
16
+ </body>
17
+
18
+ </html>