@tarve/core 0.5.0 → 0.6.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/CHANGELOG.md +46 -0
- package/README.md +54 -2
- package/dist/npm/build.js +714 -138
- package/dist/npm/cli.js +1013 -161
- package/dist/npm/embedded-assets.js +7 -2
- package/dist/npm/index.js +3096 -1084
- package/dist/npm/jsx-dev-runtime.js +1268 -0
- package/dist/npm/jsx-runtime.js +1268 -0
- package/dist/npm/native-runtime.json +3 -3
- package/dist/npm/node-build.js +299 -5
- package/dist/npm/protocol.js +1 -1
- package/dist/npm/txiki/fetch.ts +228 -0
- package/dist/npm/txiki/intl-data.ts +7 -0
- package/dist/npm/txiki/intl.test.ts +53 -0
- package/dist/npm/txiki/intl.ts +249 -0
- package/dist/npm/txiki/prelude.ts +132 -0
- package/dist/npm/txiki/runtime.ts +6 -0
- package/dist/npm/txiki/shims/buffer.ts +112 -0
- package/dist/npm/txiki/shims/child-process.ts +151 -0
- package/dist/npm/txiki/shims/crypto.ts +30 -0
- package/dist/npm/txiki/shims/events.ts +75 -0
- package/dist/npm/txiki/shims/fs-promises.ts +77 -0
- package/dist/npm/txiki/shims/fs.ts +231 -0
- package/dist/npm/txiki/shims/module.ts +8 -0
- package/dist/npm/txiki/shims/net.ts +69 -0
- package/dist/npm/txiki/shims/os.ts +72 -0
- package/dist/npm/txiki/shims/path.ts +4 -0
- package/dist/npm/txiki/shims/timers-promises.ts +9 -0
- package/dist/npm/txiki/shims/zlib.ts +9 -0
- package/dist/npm/txiki/tjs.d.ts +58 -0
- package/dist/npm/txiki/unavailable.ts +10 -0
- package/dist/types/core/build.d.ts +5 -2
- package/dist/types/core/jsx-compile.d.ts +7 -0
- package/dist/types/core/src/advanced-controls.d.ts +1 -1
- package/dist/types/core/src/app/element-events.d.ts +18 -0
- package/dist/types/core/src/app/media.d.ts +15 -0
- package/dist/types/core/src/app/requests.d.ts +25 -0
- package/dist/types/core/src/app/shadow.d.ts +7 -0
- package/dist/types/core/src/app/stats.d.ts +12 -0
- package/dist/types/core/src/app/tray.d.ts +40 -0
- package/dist/types/core/src/app-metadata.d.ts +2 -0
- package/dist/types/core/src/app.d.ts +29 -27
- package/dist/types/core/src/bridge/index.d.ts +1 -1
- package/dist/types/core/src/chat-controls.d.ts +2 -1
- package/dist/types/core/src/components/button.d.ts +1 -1
- package/dist/types/core/src/components/glass.d.ts +52 -0
- package/dist/types/core/src/components/icon.d.ts +1 -1
- package/dist/types/core/src/components/image.d.ts +1 -1
- package/dist/types/core/src/components/layout.d.ts +1 -1
- package/dist/types/core/src/components/pressable.d.ts +1 -1
- package/dist/types/core/src/components/rich-content.d.ts +1 -1
- package/dist/types/core/src/components/scroll.d.ts +2 -2
- package/dist/types/core/src/components/svg.d.ts +1 -1
- package/dist/types/core/src/components/titlebar.d.ts +15 -1
- package/dist/types/core/src/components/window.d.ts +21 -1
- package/dist/types/core/src/components.d.ts +2 -0
- package/dist/types/core/src/css-shadow.d.ts +1 -1
- package/dist/types/core/src/desktop-controls.d.ts +2 -2
- package/dist/types/core/src/embedded-assets.d.ts +3 -2
- package/dist/types/core/src/extra-controls.d.ts +1 -1
- package/dist/types/core/src/form-controls.d.ts +1 -1
- package/dist/types/core/src/index.d.ts +20 -11
- package/dist/types/core/src/inline-text.d.ts +7 -3
- package/dist/types/core/src/intrinsic-style.d.ts +1 -1
- package/dist/types/core/src/jsx-runtime.d.ts +10 -4
- package/dist/types/core/src/media-element.d.ts +3 -4
- package/dist/types/core/src/memo.d.ts +10 -0
- package/dist/types/core/src/motion.d.ts +1 -1
- package/dist/types/core/src/popups.d.ts +1 -1
- package/dist/types/core/src/protocol.d.ts +6 -0
- package/dist/types/core/src/reconciler/diff.d.ts +11 -0
- package/dist/types/core/src/reconciler/intrinsics.d.ts +24 -0
- package/dist/types/core/src/reconciler.d.ts +10 -11
- package/dist/types/core/src/render-scope.d.ts +8 -0
- package/dist/types/core/src/style.d.ts +1 -1
- package/dist/types/core/src/tailwind-palette.d.ts +1 -0
- package/dist/types/core/src/tailwind.d.ts +8 -0
- package/dist/types/core/src/test-renderer.d.ts +1 -1
- package/dist/types/core/src/text-search.d.ts +1 -1
- package/dist/types/core/src/theme.d.ts +8 -1
- package/dist/types/core/src/updates.d.ts +87 -0
- package/dist/types/core/src/virtual-list.d.ts +3 -1
- package/dist/types/core/txiki/fetch.d.ts +1 -0
- package/dist/types/core/txiki/intl-data.d.ts +6 -0
- package/dist/types/core/txiki/intl.d.ts +92 -0
- package/dist/types/core/txiki/prelude.d.ts +1 -0
- package/dist/types/core/txiki/runtime.d.ts +2 -0
- package/dist/types/core/txiki/shims/buffer.d.ts +37 -0
- package/dist/types/core/txiki/shims/child-process.d.ts +46 -0
- package/dist/types/core/txiki/shims/crypto.d.ts +16 -0
- package/dist/types/core/txiki/shims/events.d.ts +21 -0
- package/dist/types/core/txiki/shims/fs-promises.d.ts +41 -0
- package/dist/types/core/txiki/shims/fs.d.ts +44 -0
- package/dist/types/core/txiki/shims/module.d.ts +5 -0
- package/dist/types/core/txiki/shims/net.d.ts +22 -0
- package/dist/types/core/txiki/shims/os.d.ts +52 -0
- package/dist/types/core/txiki/shims/path.d.ts +3 -0
- package/dist/types/core/txiki/shims/timers-promises.d.ts +7 -0
- package/dist/types/core/txiki/shims/zlib.d.ts +11 -0
- package/dist/types/core/txiki/unavailable.d.ts +5 -0
- package/dist/types/core/txiki-build.d.ts +23 -0
- package/dist/types/core/updates-build.d.ts +35 -0
- package/dist/types/protocol/src/index.d.ts +159 -8
- package/native/linux-x64/libtarve_native.so +0 -0
- package/native/linux-x64/runtime.json +4 -4
- package/native/win32-x64/runtime.json +4 -4
- package/native/win32-x64/tarve_native.dll +0 -0
- package/package.json +3 -2
- /package/dist/types/core/{app-metadata.d.ts → package-metadata.d.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schemaVersion": 1,
|
|
3
|
-
"packageVersion": "0.
|
|
4
|
-
"protocolVersion":
|
|
3
|
+
"packageVersion": "0.6.0",
|
|
4
|
+
"protocolVersion": 59,
|
|
5
5
|
"nativeAbiVersion": 5,
|
|
6
|
-
"sourceFingerprint": "
|
|
6
|
+
"sourceFingerprint": "825110f6accde0e1d2ba89c4fc78d571b652ed43539596aacf82851f8e880e29"
|
|
7
7
|
}
|
package/dist/npm/node-build.js
CHANGED
|
@@ -324,7 +324,7 @@ var init_png = __esm(() => {
|
|
|
324
324
|
});
|
|
325
325
|
});
|
|
326
326
|
|
|
327
|
-
// packages/core/
|
|
327
|
+
// packages/core/package-metadata.ts
|
|
328
328
|
import { existsSync, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "node:fs";
|
|
329
329
|
import { basename, dirname as dirname2, extname, join, relative, resolve as resolve2 } from "node:path";
|
|
330
330
|
function fields(value, where) {
|
|
@@ -434,6 +434,7 @@ function buildMetadata(entrypoint, overrides) {
|
|
|
434
434
|
function runtimeMetadata(metadata, icon) {
|
|
435
435
|
return JSON.stringify({
|
|
436
436
|
name: metadata.name,
|
|
437
|
+
...metadata.version ? { version: metadata.version } : {},
|
|
437
438
|
...metadata.appId ? { appId: metadata.appId } : {},
|
|
438
439
|
...icon ? { icon } : {}
|
|
439
440
|
});
|
|
@@ -461,14 +462,14 @@ function writeLinuxDesktopEntry(outfile, metadata, png) {
|
|
|
461
462
|
return desktop;
|
|
462
463
|
}
|
|
463
464
|
var FIELDS, ICO_SIZES;
|
|
464
|
-
var
|
|
465
|
+
var init_package_metadata = __esm(() => {
|
|
465
466
|
init_png();
|
|
466
467
|
FIELDS = ["name", "version", "description", "publisher", "copyright", "icon", "appId"];
|
|
467
468
|
ICO_SIZES = [16, 20, 24, 32, 40, 48, 64, 96, 128, 256];
|
|
468
469
|
});
|
|
469
470
|
|
|
470
471
|
// packages/protocol/src/index.ts
|
|
471
|
-
var NATIVE_ABI_VERSION = 5, PROTOCOL_VERSION =
|
|
472
|
+
var NATIVE_ABI_VERSION = 5, PROTOCOL_VERSION = 59;
|
|
472
473
|
|
|
473
474
|
// packages/core/native-runtime.ts
|
|
474
475
|
import { createHash } from "node:crypto";
|
|
@@ -585,7 +586,7 @@ function metadataOverrides(options) {
|
|
|
585
586
|
return { name: options.name, version: options.version, description: options.description, publisher: options.publisher, copyright: options.copyright, icon: options.icon, appId: options.appId };
|
|
586
587
|
}
|
|
587
588
|
var init_build = __esm(() => {
|
|
588
|
-
|
|
589
|
+
init_package_metadata();
|
|
589
590
|
init_targets();
|
|
590
591
|
init_native_runtime();
|
|
591
592
|
init_targets();
|
|
@@ -680,6 +681,289 @@ async function targetNodeExecutable(target, version) {
|
|
|
680
681
|
}
|
|
681
682
|
var init_node_target = () => {};
|
|
682
683
|
|
|
684
|
+
// packages/core/jsx-compile.ts
|
|
685
|
+
var exports_jsx_compile = {};
|
|
686
|
+
__export(exports_jsx_compile, {
|
|
687
|
+
closeJsxCompiler: () => closeJsxCompiler,
|
|
688
|
+
compileJsx: () => compileJsx
|
|
689
|
+
});
|
|
690
|
+
async function loadParser() {
|
|
691
|
+
let modules;
|
|
692
|
+
try {
|
|
693
|
+
modules = await Promise.all([import("typescript/unstable/ast"), import("typescript/unstable/ast/is")]);
|
|
694
|
+
} catch (error) {
|
|
695
|
+
throw new Error(`compileJsx needs TypeScript 7 (npm install -D typescript@7): ${error instanceof Error ? error.message : String(error)}`);
|
|
696
|
+
}
|
|
697
|
+
const [ast, is] = modules;
|
|
698
|
+
const files = new Map([[CONFIG, JSON.stringify({ compilerOptions: { jsx: "preserve", noLib: true, noResolve: true, types: [] }, files: ["app.tsx"] })]]);
|
|
699
|
+
const normalize = (path) => path.replace(/\\/g, "/").replace(/^[A-Za-z]:/, "");
|
|
700
|
+
const options = {
|
|
701
|
+
cwd: ROOT,
|
|
702
|
+
fs: {
|
|
703
|
+
readFile: (path) => files.get(normalize(path)),
|
|
704
|
+
fileExists: (path) => files.has(normalize(path)),
|
|
705
|
+
directoryExists: (path) => {
|
|
706
|
+
const p = normalize(path).replace(/\/$/, "");
|
|
707
|
+
return p === "" || ROOT.startsWith(p);
|
|
708
|
+
},
|
|
709
|
+
getAccessibleEntries: (path) => normalize(path).replace(/\/$/, "") === ROOT ? { files: ["app.tsx", "tsconfig.json"], directories: [] } : { files: [], directories: [] },
|
|
710
|
+
realpath: (path) => path
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
const request = { openProject: CONFIG, fileChanges: { invalidateAll: true } };
|
|
714
|
+
if ((process.platform === "win32" || typeof Bun === "undefined") && process.env.TARVE_TSGO_ASYNC !== "1") {
|
|
715
|
+
const sync = await import("typescript/unstable/sync");
|
|
716
|
+
const api = new sync.API(options);
|
|
717
|
+
return {
|
|
718
|
+
ast,
|
|
719
|
+
is,
|
|
720
|
+
files,
|
|
721
|
+
parse: async () => {
|
|
722
|
+
api.clearSourceFileCache();
|
|
723
|
+
const snapshot = api.updateSnapshot(request);
|
|
724
|
+
try {
|
|
725
|
+
return snapshot.getProjects()[0].program.getSourceFile(FILE);
|
|
726
|
+
} finally {
|
|
727
|
+
snapshot.dispose();
|
|
728
|
+
}
|
|
729
|
+
},
|
|
730
|
+
close: async () => api.close()
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
const asyncApi = await import("typescript/unstable/async");
|
|
734
|
+
const api = new asyncApi.API(options);
|
|
735
|
+
return {
|
|
736
|
+
ast,
|
|
737
|
+
is,
|
|
738
|
+
files,
|
|
739
|
+
parse: async () => {
|
|
740
|
+
api.clearSourceFileCache();
|
|
741
|
+
const snapshot = await api.updateSnapshot(request);
|
|
742
|
+
try {
|
|
743
|
+
return await snapshot.getProjects()[0].program.getSourceFile(FILE);
|
|
744
|
+
} finally {
|
|
745
|
+
await snapshot.dispose();
|
|
746
|
+
}
|
|
747
|
+
},
|
|
748
|
+
close: () => api.close()
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
async function closeJsxCompiler() {
|
|
752
|
+
const current = parser;
|
|
753
|
+
parser = undefined;
|
|
754
|
+
if (current)
|
|
755
|
+
await (await current).close();
|
|
756
|
+
}
|
|
757
|
+
function constant(node, ast, ts) {
|
|
758
|
+
const isConstant = (child) => constant(child, ast, ts);
|
|
759
|
+
if (ts.isParenthesizedExpression(node))
|
|
760
|
+
return isConstant(node.expression);
|
|
761
|
+
if (ts.isNumericLiteral(node) || ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node))
|
|
762
|
+
return true;
|
|
763
|
+
if (node.kind === ast.SyntaxKind.TrueKeyword || node.kind === ast.SyntaxKind.FalseKeyword || node.kind === ast.SyntaxKind.NullKeyword)
|
|
764
|
+
return true;
|
|
765
|
+
if (ts.isIdentifier(node) && node.text === "undefined")
|
|
766
|
+
return true;
|
|
767
|
+
if (ts.isPrefixUnaryExpression(node) && (node.operator === ast.SyntaxKind.MinusToken || node.operator === ast.SyntaxKind.PlusToken))
|
|
768
|
+
return ts.isNumericLiteral(node.operand);
|
|
769
|
+
if (ts.isArrayLiteralExpression(node))
|
|
770
|
+
return node.elements.every((element) => !ts.isSpreadElement(element) && isConstant(element));
|
|
771
|
+
if (ts.isObjectLiteralExpression(node)) {
|
|
772
|
+
return node.properties.every((property) => ts.isPropertyAssignment(property) && (ts.isIdentifier(property.name) || ts.isStringLiteral(property.name) || ts.isNumericLiteral(property.name)) && isConstant(property.initializer));
|
|
773
|
+
}
|
|
774
|
+
return false;
|
|
775
|
+
}
|
|
776
|
+
async function compileJsx(source) {
|
|
777
|
+
if (!/<[A-Za-z>]/.test(source))
|
|
778
|
+
return { code: source, templates: 0 };
|
|
779
|
+
const loaded = await (parser ??= loadParser());
|
|
780
|
+
const turn = queue.then(async () => {
|
|
781
|
+
loaded.files.set(FILE, source);
|
|
782
|
+
const file = await loaded.parse();
|
|
783
|
+
if (!file || file.text !== source)
|
|
784
|
+
throw new Error("compileJsx: TypeScript returned a different parse of the file");
|
|
785
|
+
return compileFile(source, file, loaded.ast, loaded.is);
|
|
786
|
+
});
|
|
787
|
+
queue = turn.catch(() => {
|
|
788
|
+
return;
|
|
789
|
+
});
|
|
790
|
+
return turn;
|
|
791
|
+
}
|
|
792
|
+
function compileFile(source, file, ast, ts) {
|
|
793
|
+
const isConstant = (node) => constant(node, ast, ts);
|
|
794
|
+
const isJsx = (node) => ts.isJsxElement(node) || ts.isJsxSelfClosingElement(node) || ts.isJsxFragment(node);
|
|
795
|
+
const core = new Set;
|
|
796
|
+
let lastImport = 0;
|
|
797
|
+
for (const statement of file.statements) {
|
|
798
|
+
if (!ts.isImportDeclaration(statement))
|
|
799
|
+
continue;
|
|
800
|
+
lastImport = statement.end;
|
|
801
|
+
if (!ts.isStringLiteral(statement.moduleSpecifier) || !CORE.test(statement.moduleSpecifier.text))
|
|
802
|
+
continue;
|
|
803
|
+
const bindings = statement.importClause?.namedBindings;
|
|
804
|
+
if (bindings && ts.isNamedImports(bindings) && statement.importClause.phaseModifier !== ast.SyntaxKind.TypeKeyword) {
|
|
805
|
+
for (const element of bindings.elements)
|
|
806
|
+
if (!element.isTypeOnly)
|
|
807
|
+
core.add(element.name.text);
|
|
808
|
+
}
|
|
809
|
+
}
|
|
810
|
+
const shadowed = new Set;
|
|
811
|
+
const scan = (node) => {
|
|
812
|
+
const name = node.kind === ast.SyntaxKind.Parameter || ts.isVariableDeclaration(node) || ts.isFunctionDeclaration(node) || ts.isClassDeclaration(node) ? node.name : undefined;
|
|
813
|
+
if (name && ts.isIdentifier(name) && core.has(name.text))
|
|
814
|
+
shadowed.add(name.text);
|
|
815
|
+
node.forEachChild(scan);
|
|
816
|
+
};
|
|
817
|
+
file.forEachChild(scan);
|
|
818
|
+
for (const name of shadowed)
|
|
819
|
+
core.delete(name);
|
|
820
|
+
const pure = (node) => {
|
|
821
|
+
if (ts.isJsxFragment(node))
|
|
822
|
+
return true;
|
|
823
|
+
const tag = ts.isJsxElement(node) ? node.openingElement.tagName : node.tagName;
|
|
824
|
+
if (ts.isIdentifier(tag))
|
|
825
|
+
return /^[a-z]/.test(tag.text) || core.has(tag.text);
|
|
826
|
+
return false;
|
|
827
|
+
};
|
|
828
|
+
const text = (start, end) => source.slice(start, end);
|
|
829
|
+
const declarations = [];
|
|
830
|
+
function rewrite(start, end, root) {
|
|
831
|
+
const roots = [];
|
|
832
|
+
const find = (node) => {
|
|
833
|
+
if (node.end <= start || node.pos >= end)
|
|
834
|
+
return;
|
|
835
|
+
if (isJsx(node) && node.getStart() >= start && node.end <= end) {
|
|
836
|
+
roots.push(node);
|
|
837
|
+
return;
|
|
838
|
+
}
|
|
839
|
+
node.forEachChild(find);
|
|
840
|
+
};
|
|
841
|
+
find(root);
|
|
842
|
+
let out = "";
|
|
843
|
+
let at = start;
|
|
844
|
+
for (const node of roots) {
|
|
845
|
+
out += text(at, node.getStart()) + compileRoot(node);
|
|
846
|
+
at = node.end;
|
|
847
|
+
}
|
|
848
|
+
return out + text(at, end);
|
|
849
|
+
}
|
|
850
|
+
function compileRoot(node) {
|
|
851
|
+
if (!pure(node))
|
|
852
|
+
return impure(node);
|
|
853
|
+
const holes = [];
|
|
854
|
+
const events = [];
|
|
855
|
+
let key;
|
|
856
|
+
const hole = (expression, event = false) => {
|
|
857
|
+
const name = "h" + holes.length;
|
|
858
|
+
holes.push(expression);
|
|
859
|
+
if (event)
|
|
860
|
+
events.push(name);
|
|
861
|
+
return "p." + name;
|
|
862
|
+
};
|
|
863
|
+
let elements = 0;
|
|
864
|
+
function body(element, isRoot) {
|
|
865
|
+
if (!pure(element))
|
|
866
|
+
return "{" + hole(impure(element)) + "}";
|
|
867
|
+
elements++;
|
|
868
|
+
let out = "";
|
|
869
|
+
let at = element.getStart();
|
|
870
|
+
const end = element.end;
|
|
871
|
+
const attributes = ts.isJsxElement(element) ? element.openingElement.attributes : ts.isJsxSelfClosingElement(element) ? element.attributes : undefined;
|
|
872
|
+
const children = ts.isJsxElement(element) || ts.isJsxFragment(element) ? element.children : undefined;
|
|
873
|
+
const parts = [];
|
|
874
|
+
for (const attribute of attributes?.properties ?? []) {
|
|
875
|
+
if (ts.isJsxSpreadAttribute(attribute)) {
|
|
876
|
+
parts.push({ start: attribute.expression.getStart(), end: attribute.expression.end, replacement: hole(rewrite(attribute.expression.getStart(), attribute.expression.end, attribute.expression)) });
|
|
877
|
+
continue;
|
|
878
|
+
}
|
|
879
|
+
const name = attribute.name.getText();
|
|
880
|
+
const initializer = attribute.initializer;
|
|
881
|
+
if (isRoot && name === "key") {
|
|
882
|
+
key = initializer ? ts.isJsxExpression(initializer) && initializer.expression ? rewrite(initializer.expression.getStart(), initializer.expression.end, initializer.expression) : initializer.getText() : "true";
|
|
883
|
+
parts.push({ start: attribute.getStart(), end: attribute.end, replacement: "" });
|
|
884
|
+
continue;
|
|
885
|
+
}
|
|
886
|
+
if (!initializer)
|
|
887
|
+
continue;
|
|
888
|
+
if (ts.isJsxExpression(initializer) && initializer.expression && !isConstant(initializer.expression)) {
|
|
889
|
+
const expression = initializer.expression;
|
|
890
|
+
parts.push({ start: expression.getStart(), end: expression.end, replacement: hole(rewrite(expression.getStart(), expression.end, expression), EVENT.test(name)) });
|
|
891
|
+
} else if (isJsx(initializer)) {
|
|
892
|
+
const value = initializer;
|
|
893
|
+
parts.push({ start: value.getStart(), end: value.end, replacement: "{" + hole(compileRoot(value)) + "}" });
|
|
894
|
+
}
|
|
895
|
+
}
|
|
896
|
+
for (const child of children ?? []) {
|
|
897
|
+
if (ts.isJsxExpression(child)) {
|
|
898
|
+
if (!child.expression)
|
|
899
|
+
continue;
|
|
900
|
+
if (isConstant(child.expression) && !ts.isObjectLiteralExpression(child.expression) && !ts.isArrayLiteralExpression(child.expression))
|
|
901
|
+
continue;
|
|
902
|
+
parts.push({ start: child.expression.getStart(), end: child.expression.end, replacement: hole(rewrite(child.expression.getStart(), child.expression.end, child.expression)) });
|
|
903
|
+
} else if (isJsx(child)) {
|
|
904
|
+
parts.push({ start: child.getStart(), end: child.end, replacement: body(child, false) });
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
parts.sort((a, b) => a.start - b.start);
|
|
908
|
+
for (const part of parts) {
|
|
909
|
+
out += text(at, part.start) + part.replacement;
|
|
910
|
+
at = part.end;
|
|
911
|
+
}
|
|
912
|
+
return out + text(at, end);
|
|
913
|
+
}
|
|
914
|
+
const template = body(node, true);
|
|
915
|
+
if (elements < 2)
|
|
916
|
+
return impure(node);
|
|
917
|
+
const name = "__tarveTemplate" + declarations.length;
|
|
918
|
+
declarations.push(`const ${name} = __tarveCompileTemplate((p: any) => (${template}), ${JSON.stringify(events)});`);
|
|
919
|
+
const props = holes.map((expression, index) => `h${index}={${expression}}`);
|
|
920
|
+
if (key !== undefined)
|
|
921
|
+
props.unshift(`key={${key}}`);
|
|
922
|
+
return `<${name} ${props.join(" ")} />`;
|
|
923
|
+
}
|
|
924
|
+
function impure(node) {
|
|
925
|
+
let out = "";
|
|
926
|
+
let at = node.getStart();
|
|
927
|
+
const visit = (child) => {
|
|
928
|
+
if (isJsx(child) && child !== node) {
|
|
929
|
+
out += text(at, child.getStart()) + compileRoot(child);
|
|
930
|
+
at = child.end;
|
|
931
|
+
return;
|
|
932
|
+
}
|
|
933
|
+
if (ts.isJsxExpression(child) && child.expression) {
|
|
934
|
+
out += text(at, child.expression.getStart()) + rewrite(child.expression.getStart(), child.expression.end, child.expression);
|
|
935
|
+
at = child.expression.end;
|
|
936
|
+
return;
|
|
937
|
+
}
|
|
938
|
+
if (ts.isJsxSpreadAttribute(child)) {
|
|
939
|
+
out += text(at, child.expression.getStart()) + rewrite(child.expression.getStart(), child.expression.end, child.expression);
|
|
940
|
+
at = child.expression.end;
|
|
941
|
+
return;
|
|
942
|
+
}
|
|
943
|
+
child.forEachChild(visit);
|
|
944
|
+
};
|
|
945
|
+
node.forEachChild(visit);
|
|
946
|
+
return out + text(at, node.end);
|
|
947
|
+
}
|
|
948
|
+
const body = rewrite(lastImport, source.length, file);
|
|
949
|
+
if (!declarations.length)
|
|
950
|
+
return { code: source, templates: 0 };
|
|
951
|
+
const code = text(0, lastImport) + `
|
|
952
|
+
import { template as __tarveCompileTemplate } from "@tarve/core";
|
|
953
|
+
` + declarations.join(`
|
|
954
|
+
`) + `
|
|
955
|
+
` + body;
|
|
956
|
+
return { code, templates: declarations.length };
|
|
957
|
+
}
|
|
958
|
+
var ROOT = "/tarve-jsx", FILE, CONFIG, parser, queue, CORE, EVENT;
|
|
959
|
+
var init_jsx_compile = __esm(() => {
|
|
960
|
+
FILE = ROOT + "/app.tsx";
|
|
961
|
+
CONFIG = ROOT + "/tsconfig.json";
|
|
962
|
+
queue = Promise.resolve();
|
|
963
|
+
CORE = /^(?:@tarve\/core|tarve)(?:\/.*)?$/;
|
|
964
|
+
EVENT = /^on[A-Z]/;
|
|
965
|
+
});
|
|
966
|
+
|
|
683
967
|
// packages/core/windows-executable.ts
|
|
684
968
|
var exports_windows_executable = {};
|
|
685
969
|
__export(exports_windows_executable, {
|
|
@@ -793,6 +1077,14 @@ async function buildNode(options) {
|
|
|
793
1077
|
plugins: [fileImportAttributes, {
|
|
794
1078
|
name: "tarve-node-runtime",
|
|
795
1079
|
setup(build) {
|
|
1080
|
+
if (options.compileJsx) {
|
|
1081
|
+
build.onLoad({ filter: /\.[jt]sx$/ }, async (args) => {
|
|
1082
|
+
if (/[\\/]node_modules[\\/]/.test(args.path) || args.path.startsWith(join4(root, "src")))
|
|
1083
|
+
return;
|
|
1084
|
+
await Promise.resolve().then(() => init_jsx_compile());
|
|
1085
|
+
return { contents: (await compileJsx(readFileSync5(args.path, "utf8"))).code, loader: args.path.endsWith(".jsx") ? "jsx" : "tsx", resolveDir: dirname4(args.path) };
|
|
1086
|
+
});
|
|
1087
|
+
}
|
|
796
1088
|
if (source) {
|
|
797
1089
|
build.onResolve({ filter: /^@tarve\/core(?:\/(?:jsx-runtime|jsx-dev-runtime))?$/ }, (args) => {
|
|
798
1090
|
const entry = args.path.slice("@tarve/core".length) || "/index";
|
|
@@ -844,6 +1136,8 @@ async function buildNode(options) {
|
|
|
844
1136
|
writeLinuxDesktopEntry(outfile, metadata, images?.png);
|
|
845
1137
|
return outfile;
|
|
846
1138
|
} finally {
|
|
1139
|
+
if (options.compileJsx)
|
|
1140
|
+
await (await Promise.resolve().then(() => (init_jsx_compile(), exports_jsx_compile))).closeJsxCompiler();
|
|
847
1141
|
await rm(temporary, { recursive: true, force: true });
|
|
848
1142
|
}
|
|
849
1143
|
}
|
|
@@ -854,7 +1148,7 @@ var init_node_build = __esm(() => {
|
|
|
854
1148
|
init_esbuild_file_imports();
|
|
855
1149
|
init_targets();
|
|
856
1150
|
init_build();
|
|
857
|
-
|
|
1151
|
+
init_package_metadata();
|
|
858
1152
|
init_native_runtime();
|
|
859
1153
|
init_node_target();
|
|
860
1154
|
});
|
package/dist/npm/protocol.js
CHANGED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fetch for txiki.js with Node and Bun semantics. txiki.js's own fetch is a browser
|
|
3
|
+
* XMLHttpRequest over libwebsockets: it always adds its own Origin, Pragma and
|
|
4
|
+
* Cache-Control headers (servers like Google's reject a request whose Origin the app
|
|
5
|
+
* set too) and offers no streaming. This client speaks HTTP/1.1 over tjs.connect
|
|
6
|
+
* ("tcp" / "tls"): exactly the headers the app sets, redirects, gzip/deflate, chunked
|
|
7
|
+
* bodies streamed as they arrive, and AbortSignal. Other schemes use txiki's fetch.
|
|
8
|
+
*/
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const decoder = new TextDecoder();
|
|
11
|
+
const MAX_REDIRECTS = 20;
|
|
12
|
+
|
|
13
|
+
interface Connection {
|
|
14
|
+
readable: ReadableStream<Uint8Array>;
|
|
15
|
+
writable: WritableStream<Uint8Array>;
|
|
16
|
+
close(): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async function open(url: URL): Promise<Connection> {
|
|
20
|
+
const secure = url.protocol === "https:";
|
|
21
|
+
const port = Number(url.port || (secure ? 443 : 80));
|
|
22
|
+
const host = url.hostname.replace(/^\[|\]$/g, "");
|
|
23
|
+
const socket = await (tjs as unknown as { connect(transport: string, host: string, port: number): Promise<{ opened: Promise<{ readable: ReadableStream<Uint8Array>; writable: WritableStream<Uint8Array> }>; close(): void }> })
|
|
24
|
+
.connect(secure ? "tls" : "tcp", host, port);
|
|
25
|
+
const { readable, writable } = await socket.opened;
|
|
26
|
+
return { readable, writable, close: () => { try { socket.close(); } catch { /* closed */ } } };
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async function bodyBytes(body: unknown): Promise<Uint8Array | undefined> {
|
|
30
|
+
if (body == null) return undefined;
|
|
31
|
+
if (typeof body === "string") return encoder.encode(body);
|
|
32
|
+
if (body instanceof Uint8Array) return body;
|
|
33
|
+
if (body instanceof ArrayBuffer) return new Uint8Array(body);
|
|
34
|
+
if (ArrayBuffer.isView(body)) return new Uint8Array(body.buffer, body.byteOffset, body.byteLength);
|
|
35
|
+
if (body instanceof URLSearchParams) return encoder.encode(body.toString());
|
|
36
|
+
// Blob, FormData, ReadableStream: let Response serialize it (FormData gets its boundary type).
|
|
37
|
+
return new Uint8Array(await new Response(body as BodyInit).arrayBuffer());
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function defaultContentType(body: unknown): string | undefined {
|
|
41
|
+
if (typeof body === "string") return "text/plain;charset=UTF-8";
|
|
42
|
+
if (body instanceof URLSearchParams) return "application/x-www-form-urlencoded;charset=UTF-8";
|
|
43
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) return new Response(body).headers.get("content-type") ?? undefined;
|
|
44
|
+
if (typeof Blob !== "undefined" && body instanceof Blob && body.type) return body.type;
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Buffered reads over the socket: the head line by line, the body by length. */
|
|
49
|
+
class Reader {
|
|
50
|
+
private buffer = new Uint8Array(0);
|
|
51
|
+
private done = false;
|
|
52
|
+
constructor(private readonly reader: ReadableStreamDefaultReader<Uint8Array>) {}
|
|
53
|
+
|
|
54
|
+
private async fill(): Promise<boolean> {
|
|
55
|
+
if (this.done) return false;
|
|
56
|
+
const { done, value } = await this.reader.read();
|
|
57
|
+
if (done || !value) { this.done = true; return false; }
|
|
58
|
+
const next = new Uint8Array(this.buffer.length + value.length);
|
|
59
|
+
next.set(this.buffer);
|
|
60
|
+
next.set(value, this.buffer.length);
|
|
61
|
+
this.buffer = next;
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async line(): Promise<string | undefined> {
|
|
66
|
+
for (;;) {
|
|
67
|
+
const at = this.buffer.indexOf(10);
|
|
68
|
+
if (at >= 0) {
|
|
69
|
+
const line = decoder.decode(this.buffer.subarray(0, at)).replace(/\r$/, "");
|
|
70
|
+
this.buffer = this.buffer.subarray(at + 1);
|
|
71
|
+
return line;
|
|
72
|
+
}
|
|
73
|
+
if (!await this.fill()) return undefined;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Up to `max` bytes; undefined at end of stream. */
|
|
78
|
+
async chunk(max = Infinity): Promise<Uint8Array | undefined> {
|
|
79
|
+
if (!this.buffer.length && !await this.fill()) return undefined;
|
|
80
|
+
const size = Math.min(max, this.buffer.length);
|
|
81
|
+
const out = this.buffer.subarray(0, size);
|
|
82
|
+
this.buffer = this.buffer.subarray(size);
|
|
83
|
+
return out;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
cancel(): void {
|
|
87
|
+
this.reader.cancel().catch(() => {});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function abortError(signal: AbortSignal | null | undefined): unknown {
|
|
92
|
+
return signal?.reason ?? new DOMException("The operation was aborted.", "AbortError");
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async function request(url: URL, method: string, headers: Headers, body: Uint8Array | undefined, signal: AbortSignal | null | undefined): Promise<Response> {
|
|
96
|
+
if (signal?.aborted) throw abortError(signal);
|
|
97
|
+
// Closing the socket does not settle a pending read: race every wait against the abort.
|
|
98
|
+
let connection: Connection | undefined;
|
|
99
|
+
const onAbort = () => connection?.close();
|
|
100
|
+
let rejectAbort = () => {};
|
|
101
|
+
const abortion = signal ? new Promise<never>((_, reject) => { rejectAbort = () => reject(abortError(signal)); signal.addEventListener("abort", rejectAbort, { once: true }); }) : undefined;
|
|
102
|
+
abortion?.catch(() => {});
|
|
103
|
+
const race = <T>(promise: Promise<T>): Promise<T> => abortion ? Promise.race([promise, abortion]) : promise;
|
|
104
|
+
signal?.addEventListener("abort", onAbort, { once: true });
|
|
105
|
+
try {
|
|
106
|
+
const socket = connection = await race(open(url));
|
|
107
|
+
const lines = [`${method} ${url.pathname || "/"}${url.search} HTTP/1.1`];
|
|
108
|
+
if (!headers.has("host")) lines.push(`host: ${url.host}`);
|
|
109
|
+
if (!headers.has("accept")) lines.push("accept: */*");
|
|
110
|
+
if (!headers.has("accept-encoding")) lines.push("accept-encoding: gzip, deflate");
|
|
111
|
+
if (!headers.has("user-agent")) lines.push(`user-agent: tarve (txiki.js ${tjs.version})`);
|
|
112
|
+
lines.push("connection: close");
|
|
113
|
+
headers.forEach((value, name) => { if (name !== "connection" && name !== "content-length") lines.push(`${name}: ${value}`); });
|
|
114
|
+
if (body || method === "POST" || method === "PUT" || method === "PATCH") lines.push(`content-length: ${body?.length ?? 0}`);
|
|
115
|
+
const writer = socket.writable.getWriter();
|
|
116
|
+
await race(writer.write(encoder.encode(lines.join("\r\n") + "\r\n\r\n")));
|
|
117
|
+
if (body?.length) await race(writer.write(body));
|
|
118
|
+
writer.releaseLock();
|
|
119
|
+
|
|
120
|
+
const reader = new Reader(socket.readable.getReader());
|
|
121
|
+
let status = 0, statusText = "";
|
|
122
|
+
const responseHeaders = new Headers();
|
|
123
|
+
// Skip interim 1xx responses (100 Continue).
|
|
124
|
+
do {
|
|
125
|
+
const statusLine = await race(reader.line());
|
|
126
|
+
if (statusLine === undefined) throw new TypeError(`fetch failed: ${url.host} closed the connection`);
|
|
127
|
+
const match = /^HTTP\/\d(?:\.\d)? (\d{3}) ?(.*)$/.exec(statusLine);
|
|
128
|
+
if (!match) throw new TypeError(`fetch failed: malformed response from ${url.host}`);
|
|
129
|
+
status = Number(match[1]);
|
|
130
|
+
statusText = match[2]!;
|
|
131
|
+
for (;;) {
|
|
132
|
+
const line = await race(reader.line());
|
|
133
|
+
if (line === undefined || line === "") break;
|
|
134
|
+
const colon = line.indexOf(":");
|
|
135
|
+
if (colon > 0 && status >= 200) responseHeaders.append(line.slice(0, colon).trim(), line.slice(colon + 1).trim());
|
|
136
|
+
}
|
|
137
|
+
} while (status < 200);
|
|
138
|
+
|
|
139
|
+
const empty = method === "HEAD" || status === 204 || status === 304;
|
|
140
|
+
const chunked = /\bchunked\b/i.test(responseHeaders.get("transfer-encoding") ?? "");
|
|
141
|
+
// A missing or malformed Content-Length reads to the end of the connection.
|
|
142
|
+
const declared = Number(responseHeaders.get("content-length") ?? NaN);
|
|
143
|
+
let remaining = empty ? 0 : !chunked && Number.isSafeInteger(declared) && declared >= 0 ? declared : Infinity;
|
|
144
|
+
let chunkLeft = 0, finished = empty;
|
|
145
|
+
const finish = () => { finished = true; signal?.removeEventListener("abort", onAbort); signal?.removeEventListener("abort", rejectAbort); reader.cancel(); socket.close(); };
|
|
146
|
+
let stream: ReadableStream<Uint8Array> = new ReadableStream<Uint8Array>({
|
|
147
|
+
async pull(controller) {
|
|
148
|
+
try {
|
|
149
|
+
if (finished) { controller.close(); return; }
|
|
150
|
+
if (chunked) {
|
|
151
|
+
if (chunkLeft === 0) {
|
|
152
|
+
const size = parseInt((await race(reader.line())) ?? "0", 16);
|
|
153
|
+
if (!size) { finish(); controller.close(); return; }
|
|
154
|
+
chunkLeft = size;
|
|
155
|
+
}
|
|
156
|
+
const data = await race(reader.chunk(chunkLeft));
|
|
157
|
+
if (!data) throw new TypeError("fetch failed: connection closed inside a chunk");
|
|
158
|
+
chunkLeft -= data.length;
|
|
159
|
+
if (chunkLeft === 0) await race(reader.line());
|
|
160
|
+
controller.enqueue(data.slice());
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (remaining <= 0) { finish(); controller.close(); return; }
|
|
164
|
+
const data = await race(reader.chunk(remaining));
|
|
165
|
+
if (!data) {
|
|
166
|
+
if (remaining !== Infinity) throw new TypeError("fetch failed: connection closed before the body ended");
|
|
167
|
+
finish(); controller.close(); return;
|
|
168
|
+
}
|
|
169
|
+
remaining -= data.length;
|
|
170
|
+
controller.enqueue(data.slice());
|
|
171
|
+
} catch (error) {
|
|
172
|
+
finish();
|
|
173
|
+
controller.error(signal?.aborted ? abortError(signal) : error);
|
|
174
|
+
}
|
|
175
|
+
},
|
|
176
|
+
cancel() { finish(); },
|
|
177
|
+
});
|
|
178
|
+
if (empty) finish();
|
|
179
|
+
const encoding = (responseHeaders.get("content-encoding") ?? "").toLowerCase();
|
|
180
|
+
if (!empty && (encoding === "gzip" || encoding === "deflate" || encoding === "x-gzip")) {
|
|
181
|
+
stream = stream.pipeThrough(new DecompressionStream(encoding === "deflate" ? "deflate" : "gzip") as unknown as ReadableWritablePair<Uint8Array, Uint8Array>);
|
|
182
|
+
}
|
|
183
|
+
const response = new Response(empty || status === 101 ? null : stream, { status: status === 101 ? 200 : status, statusText, headers: responseHeaders });
|
|
184
|
+
Object.defineProperty(response, "url", { value: url.href });
|
|
185
|
+
return response;
|
|
186
|
+
} catch (error) {
|
|
187
|
+
signal?.removeEventListener("abort", onAbort);
|
|
188
|
+
signal?.removeEventListener("abort", rejectAbort);
|
|
189
|
+
connection?.close();
|
|
190
|
+
throw signal?.aborted ? abortError(signal) : error;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function createFetch(fallback: typeof fetch): typeof fetch {
|
|
195
|
+
return (async (input: RequestInfo | URL, init: RequestInit = {}) => {
|
|
196
|
+
const source = typeof input === "object" && !(input instanceof URL) ? input as Request : undefined;
|
|
197
|
+
let url = new URL(source ? source.url : String(input));
|
|
198
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") return fallback(input, init);
|
|
199
|
+
let method = (init.method ?? source?.method ?? "GET").toUpperCase();
|
|
200
|
+
const headers = new Headers(init.headers ?? source?.headers);
|
|
201
|
+
const rawBody = init.body !== undefined ? init.body : source && method !== "GET" && method !== "HEAD" ? await source.arrayBuffer() : undefined;
|
|
202
|
+
const type = defaultContentType(rawBody);
|
|
203
|
+
if (type && !headers.has("content-type")) headers.set("content-type", type);
|
|
204
|
+
let body = await bodyBytes(rawBody);
|
|
205
|
+
const signal = init.signal ?? source?.signal;
|
|
206
|
+
const redirect = init.redirect ?? source?.redirect ?? "follow";
|
|
207
|
+
for (let redirects = 0; ; redirects++) {
|
|
208
|
+
const response = await request(url, method, headers, body, signal);
|
|
209
|
+
const location = response.headers.get("location");
|
|
210
|
+
if (redirect === "manual" || response.status < 300 || response.status > 399 || response.status === 304 || !location) {
|
|
211
|
+
if (redirects) Object.defineProperty(response, "redirected", { value: true });
|
|
212
|
+
return response;
|
|
213
|
+
}
|
|
214
|
+
if (redirect === "error") throw new TypeError(`fetch failed: redirect to ${location}`);
|
|
215
|
+
if (redirects >= MAX_REDIRECTS) throw new TypeError("fetch failed: too many redirects");
|
|
216
|
+
await response.body?.cancel();
|
|
217
|
+
const next = new URL(location, url);
|
|
218
|
+
if (response.status === 303 || ((response.status === 301 || response.status === 302) && method === "POST")) {
|
|
219
|
+
method = "GET";
|
|
220
|
+
body = undefined;
|
|
221
|
+
headers.delete("content-type");
|
|
222
|
+
}
|
|
223
|
+
// Credentials stay with their origin, as in browsers and Node.
|
|
224
|
+
if (next.origin !== url.origin) { headers.delete("authorization"); headers.delete("cookie"); }
|
|
225
|
+
url = next;
|
|
226
|
+
}
|
|
227
|
+
}) as typeof fetch;
|
|
228
|
+
}
|