@lokascript/vite-plugin 1.1.4 → 1.2.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/dist/index.cjs +55 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +62 -22
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1686,28 +1686,34 @@ function generateBundleCode(config) {
|
|
|
1686
1686
|
htmxIntegration = false,
|
|
1687
1687
|
globalName = "hyperfixi",
|
|
1688
1688
|
positionalExpressions = false,
|
|
1689
|
-
parserImportPath = "../parser/hybrid",
|
|
1690
1689
|
autoInit = true,
|
|
1691
|
-
esModule = true
|
|
1690
|
+
esModule = true,
|
|
1691
|
+
parserType = "hybrid"
|
|
1692
1692
|
} = config;
|
|
1693
1693
|
const needsStyleHelpers = commands.some((cmd) => import_bundle_generator.STYLE_COMMANDS.includes(cmd));
|
|
1694
1694
|
const needsElementArrayHelper = commands.some((cmd) => import_bundle_generator.ELEMENT_ARRAY_COMMANDS.includes(cmd));
|
|
1695
|
+
const needsMorphlex = commands.some((cmd) => import_bundle_generator.MORPH_COMMANDS.includes(cmd));
|
|
1695
1696
|
const hasBlocks = blocks.length > 0;
|
|
1696
1697
|
const hasReturn = commands.includes("return");
|
|
1697
1698
|
const commandCases = commands.filter((cmd) => COMMAND_IMPLEMENTATIONS[cmd]).map((cmd) => COMMAND_IMPLEMENTATIONS[cmd]).join("\n");
|
|
1698
1699
|
const blockCases = blocks.filter((block) => BLOCK_IMPLEMENTATIONS[block]).map((block) => BLOCK_IMPLEMENTATIONS[block]).join("\n");
|
|
1700
|
+
const parserTemplate = parserType === "lite" ? import_bundle_generator.LITE_PARSER_TEMPLATE : import_bundle_generator.HYBRID_PARSER_TEMPLATE;
|
|
1701
|
+
const morphlexImport = needsMorphlex ? `import { morph as morphlexMorph, morphInner as morphlexMorphInner } from 'morphlex';
|
|
1702
|
+
|
|
1703
|
+
` : "";
|
|
1699
1704
|
return `/**
|
|
1700
1705
|
* LokaScript ${name} Bundle (Auto-Generated)
|
|
1701
1706
|
*
|
|
1702
1707
|
* Generated by: @lokascript/vite-plugin
|
|
1708
|
+
* Parser: ${parserType}
|
|
1703
1709
|
* Commands: ${commands.join(", ")}${blocks.length > 0 ? `
|
|
1704
|
-
* Blocks: ${blocks.join(", ")}` : ""}${positionalExpressions ? "\n * Positional expressions: enabled" : ""}
|
|
1710
|
+
* Blocks: ${blocks.join(", ")}` : ""}${positionalExpressions ? "\n * Positional expressions: enabled" : ""}${needsMorphlex ? "\n * Morphing: morphlex (~2.5KB)" : ""}
|
|
1705
1711
|
*
|
|
1706
1712
|
* DO NOT EDIT - This file is automatically regenerated.
|
|
1707
1713
|
*/
|
|
1708
1714
|
|
|
1709
|
-
//
|
|
1710
|
-
|
|
1715
|
+
${morphlexImport}// Embedded ${parserType} parser (no external dependencies)
|
|
1716
|
+
${parserTemplate}
|
|
1711
1717
|
|
|
1712
1718
|
// Runtime state
|
|
1713
1719
|
const globalVars = new Map();
|
|
@@ -2006,8 +2012,7 @@ function processElement(el) {
|
|
|
2006
2012
|
if (!code) return;
|
|
2007
2013
|
|
|
2008
2014
|
try {
|
|
2009
|
-
const
|
|
2010
|
-
const ast = parser.parse();
|
|
2015
|
+
const ast = ${parserType === "lite" ? "parseLite(code)" : "new HybridParser(code).parse()"};
|
|
2011
2016
|
executeAST(ast, el);
|
|
2012
2017
|
} catch (err) {
|
|
2013
2018
|
console.error('LokaScript ${name} error:', err, 'Code:', code);
|
|
@@ -2023,14 +2028,12 @@ const api = {
|
|
|
2023
2028
|
version: '1.0.0-${name.toLowerCase().replace(/\s+/g, "-")}',
|
|
2024
2029
|
|
|
2025
2030
|
parse(code) {
|
|
2026
|
-
|
|
2027
|
-
return parser.parse();
|
|
2031
|
+
return ${parserType === "lite" ? "parseLite(code)" : "new HybridParser(code).parse()"};
|
|
2028
2032
|
},
|
|
2029
2033
|
|
|
2030
2034
|
async execute(code, element) {
|
|
2031
2035
|
const me = element || document.body;
|
|
2032
|
-
const
|
|
2033
|
-
const ast = parser.parse();
|
|
2036
|
+
const ast = ${parserType === "lite" ? "parseLite(code)" : "new HybridParser(code).parse()"};
|
|
2034
2037
|
return executeAST(ast, me);
|
|
2035
2038
|
},
|
|
2036
2039
|
|
|
@@ -2042,7 +2045,7 @@ const api = {
|
|
|
2042
2045
|
|
|
2043
2046
|
commands: ${JSON.stringify(commands)},
|
|
2044
2047
|
${blocks.length > 0 ? `blocks: ${JSON.stringify(blocks)},` : ""}
|
|
2045
|
-
parserName: '
|
|
2048
|
+
parserName: '${parserType}',
|
|
2046
2049
|
};
|
|
2047
2050
|
${autoInit ? `
|
|
2048
2051
|
if (typeof window !== 'undefined') {
|
|
@@ -2082,6 +2085,17 @@ var Generator = class {
|
|
|
2082
2085
|
if (commands.length === 0 && blocks.length === 0 && !positional && !semanticConfig.enabled) {
|
|
2083
2086
|
return this.generateEmptyBundle(options);
|
|
2084
2087
|
}
|
|
2088
|
+
const unsupportedCommands = this.getUnsupportedCommands(commands);
|
|
2089
|
+
if (unsupportedCommands.length > 0) {
|
|
2090
|
+
if (this.debug) {
|
|
2091
|
+
console.log(
|
|
2092
|
+
`[hyperfixi] Commands detected that require full runtime: ${unsupportedCommands.join(", ")}
|
|
2093
|
+
Falling back to full browser bundle for complete functionality.`
|
|
2094
|
+
);
|
|
2095
|
+
}
|
|
2096
|
+
return this.generateDevFallback("full");
|
|
2097
|
+
}
|
|
2098
|
+
const parserType = (0, import_bundle_generator.canUseLiteParser)(commands, blocks, positional) ? "lite" : "hybrid";
|
|
2085
2099
|
const config = {
|
|
2086
2100
|
name: options.bundleName ?? "ViteAutoGenerated",
|
|
2087
2101
|
commands,
|
|
@@ -2089,8 +2103,7 @@ var Generator = class {
|
|
|
2089
2103
|
positionalExpressions: positional,
|
|
2090
2104
|
htmxIntegration: options.htmx ?? usage.htmx?.hasHtmxAttributes ?? false,
|
|
2091
2105
|
globalName: options.globalName ?? "hyperfixi",
|
|
2092
|
-
|
|
2093
|
-
parserImportPath: "@lokascript/core/parser/hybrid",
|
|
2106
|
+
parserType,
|
|
2094
2107
|
autoInit: true,
|
|
2095
2108
|
esModule: true
|
|
2096
2109
|
};
|
|
@@ -2100,7 +2113,8 @@ var Generator = class {
|
|
|
2100
2113
|
blocks,
|
|
2101
2114
|
positional,
|
|
2102
2115
|
htmx: config.htmxIntegration,
|
|
2103
|
-
semantic: semanticConfig.enabled
|
|
2116
|
+
semantic: semanticConfig.enabled,
|
|
2117
|
+
parserType
|
|
2104
2118
|
};
|
|
2105
2119
|
if (semanticConfig.enabled && semanticConfig.bundleType) {
|
|
2106
2120
|
const sizeInfo = getSemanticBundleSize(semanticConfig.bundleType);
|
|
@@ -2135,7 +2149,7 @@ var Generator = class {
|
|
|
2135
2149
|
bundleCode = bundleCode.slice(0, parserImportEnd) + semanticCode + "\n\n" + bundleCode.slice(parserImportEnd);
|
|
2136
2150
|
}
|
|
2137
2151
|
bundleCode = bundleCode.replace(
|
|
2138
|
-
/function processElement\(el\) \{\s*const code = el\.getAttribute\('_'\);\s*if \(!code\) return;\s*try \{\s*const
|
|
2152
|
+
/function processElement\(el\) \{\s*const code = el\.getAttribute\('_'\);\s*if \(!code\) return;\s*try \{\s*const ast = (?:new HybridParser\(code\)\.parse\(\)|parseLite\(code\));/g,
|
|
2139
2153
|
`function processElement(el) {
|
|
2140
2154
|
const code = el.getAttribute('_');
|
|
2141
2155
|
if (!code) return;
|
|
@@ -2144,27 +2158,47 @@ var Generator = class {
|
|
|
2144
2158
|
const ast = parseWithSemantic(code);`
|
|
2145
2159
|
);
|
|
2146
2160
|
bundleCode = bundleCode.replace(
|
|
2147
|
-
/parse\(code\) \{\s*
|
|
2161
|
+
/parse\(code\) \{\s*return (?:new HybridParser\(code\)\.parse\(\)|parseLite\(code\));/g,
|
|
2148
2162
|
`parse(code, lang = null) {
|
|
2149
2163
|
return parseWithSemantic(code, lang);`
|
|
2150
2164
|
);
|
|
2151
2165
|
bundleCode = bundleCode.replace(
|
|
2152
|
-
/async execute\(code, element\) \{\s*const me = element \|\| document\.body;\s*const
|
|
2166
|
+
/async execute\(code, element\) \{\s*const me = element \|\| document\.body;\s*const ast = (?:new HybridParser\(code\)\.parse\(\)|parseLite\(code\));/g,
|
|
2153
2167
|
`async execute(code, element, lang = null) {
|
|
2154
2168
|
const me = element || document.body;
|
|
2155
2169
|
const ast = parseWithSemantic(code, lang);`
|
|
2156
2170
|
);
|
|
2157
2171
|
if (semanticExports.length > 0) {
|
|
2158
|
-
const
|
|
2172
|
+
const apiExportsMarkerRegex = /parserName: '(?:lite|hybrid)',/;
|
|
2159
2173
|
const additionalApiProps = semanticExports.map((exp) => ` ${exp},`).join("\n");
|
|
2160
2174
|
bundleCode = bundleCode.replace(
|
|
2161
|
-
|
|
2162
|
-
`parserName: '
|
|
2175
|
+
apiExportsMarkerRegex,
|
|
2176
|
+
`parserName: 'semantic',
|
|
2163
2177
|
${additionalApiProps}`
|
|
2164
2178
|
);
|
|
2165
2179
|
}
|
|
2166
2180
|
return bundleCode;
|
|
2167
2181
|
}
|
|
2182
|
+
/**
|
|
2183
|
+
* Get commands that require the full runtime and are not available in generated bundles
|
|
2184
|
+
*/
|
|
2185
|
+
getUnsupportedCommands(commands) {
|
|
2186
|
+
const unsupported = [];
|
|
2187
|
+
for (const cmd of commands) {
|
|
2188
|
+
if (import_bundle_generator.FULL_RUNTIME_ONLY_COMMANDS.includes(cmd)) {
|
|
2189
|
+
unsupported.push(cmd);
|
|
2190
|
+
} else if (!(0, import_bundle_generator.isAvailableCommand)(cmd) && !COMMAND_IMPLEMENTATIONS[cmd]) {
|
|
2191
|
+
unsupported.push(cmd);
|
|
2192
|
+
}
|
|
2193
|
+
}
|
|
2194
|
+
return unsupported;
|
|
2195
|
+
}
|
|
2196
|
+
/**
|
|
2197
|
+
* Check if any commands require full runtime and should trigger fallback
|
|
2198
|
+
*/
|
|
2199
|
+
requiresFullRuntime(commands) {
|
|
2200
|
+
return this.getUnsupportedCommands(commands).length > 0;
|
|
2201
|
+
}
|
|
2168
2202
|
/**
|
|
2169
2203
|
* Generate an empty bundle when no hyperscript is detected
|
|
2170
2204
|
*/
|