@octane-xplat/patches 0.0.1 → 0.10.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.
@@ -0,0 +1,354 @@
1
+ diff --git a/helpers/ts-config-paths.js b/helpers/ts-config-paths.js
2
+ index 27013b5c8f78a72b6e6df903ac36f72fc0d75c1a..53a2e7d489ab91593cbec47ee6fb640fc56c786f 100644
3
+ --- a/helpers/ts-config-paths.js
4
+ +++ b/helpers/ts-config-paths.js
5
+ @@ -113,15 +113,20 @@ function resolveTsConfigPath(fullPath, platform, verbose, debugId) {
6
+ if (verbose && debugId) {
7
+ console.log(`📁 TypeScript path candidate: ${debugId} -> ${fullPath}`);
8
+ }
9
+ + // `.mobile` is the shared ios/android suffix tier — it sits between the os
10
+ + // qualifier and the unsuffixed default. Probing it per extension keeps
11
+ + // paths-mapped imports consistent with the bundler's extension chain.
12
+ + const suffixes = platform === 'ios' || platform === 'android' ? [platform, 'mobile'] : platform ? [platform] : [];
13
+ if (fs.existsSync(fullPath) && fs.statSync(fullPath).isDirectory()) {
14
+ - const platformIndexPatterns = [`index.${platform}.ts`, `index.${platform}.js`, `index.${platform}.mjs`];
15
+ - for (const indexFile of platformIndexPatterns) {
16
+ - const indexPath = path.join(fullPath, indexFile);
17
+ - if (fs.existsSync(indexPath)) {
18
+ - if (verbose) {
19
+ - console.log(`📁 Found platform-specific directory index: ${indexPath}`);
20
+ + for (const suffix of suffixes) {
21
+ + for (const ext of ['.ts', '.js', '.mjs']) {
22
+ + const indexPath = path.join(fullPath, `index.${suffix}${ext}`);
23
+ + if (fs.existsSync(indexPath)) {
24
+ + if (verbose) {
25
+ + console.log(`📁 Found platform-specific directory index: ${indexPath}`);
26
+ + }
27
+ + return indexPath;
28
+ }
29
+ - return indexPath;
30
+ }
31
+ }
32
+ for (const indexFile of ['index.ts', 'index.js', 'index.mjs']) {
33
+ @@ -135,12 +140,14 @@ function resolveTsConfigPath(fullPath, platform, verbose, debugId) {
34
+ }
35
+ }
36
+ for (const ext of ['.ts', '.js', '.mjs']) {
37
+ - const platformPath = `${fullPath}.${platform}${ext}`;
38
+ - if (fs.existsSync(platformPath)) {
39
+ - if (verbose) {
40
+ - console.log(`📁 Found platform-specific file: ${platformPath}`);
41
+ + for (const suffix of suffixes) {
42
+ + const platformPath = `${fullPath}.${suffix}${ext}`;
43
+ + if (fs.existsSync(platformPath)) {
44
+ + if (verbose) {
45
+ + console.log(`📁 Found platform-specific file: ${platformPath}`);
46
+ + }
47
+ + return platformPath;
48
+ }
49
+ - return platformPath;
50
+ }
51
+ const basePath = `${fullPath}${ext}`;
52
+ if (fs.existsSync(basePath)) {
53
+ diff --git a/helpers/typescript-check.js b/helpers/typescript-check.js
54
+ index a05696b679b3feecd1bafa267de44b59db559162..06648067a3fcf7f8c74437a82b94ec01e74a541c 100644
55
+ --- a/helpers/typescript-check.js
56
+ +++ b/helpers/typescript-check.js
57
+ @@ -7,14 +7,16 @@ import { getProjectRootPath, getProjectTSConfigPath } from './project.js';
58
+ import { loadTypeScript } from './typescript.js';
59
+ const require = createRequire(import.meta.url);
60
+ function getModuleSuffixes(platform) {
61
+ + // `.mobile` is the shared ios/android suffix tier — it sits between the os
62
+ + // qualifier and `.native`, matching the bundler's extension chain.
63
+ if (platform === 'android') {
64
+ - return ['.android', '.native', ''];
65
+ + return ['.android', '.mobile', '.native', ''];
66
+ }
67
+ if (platform === 'ios') {
68
+ - return ['.ios', '.native', ''];
69
+ + return ['.ios', '.mobile', '.native', ''];
70
+ }
71
+ if (platform === 'visionos') {
72
+ - return ['.visionos', '.ios', '.native', ''];
73
+ + return ['.visionos', '.ios', '.mobile', '.native', ''];
74
+ }
75
+ return ['.native', ''];
76
+ }
77
+ diff --git a/hmr/server/deps-bundle.js b/hmr/server/deps-bundle.js
78
+ index 8f2fa15556244f7ef811b5e2ea0fc6a19bab74d3..80137262ec46d347d39a7ee12d66d649b5f909f5 100644
79
+ --- a/hmr/server/deps-bundle.js
80
+ +++ b/hmr/server/deps-bundle.js
81
+ @@ -53,6 +53,7 @@
82
+ import { existsSync, mkdirSync, readdirSync, readFileSync, realpathSync, statSync, unlinkSync, writeFileSync } from 'node:fs';
83
+ import * as path from 'node:path';
84
+ import { createHash } from 'node:crypto';
85
+ +import { createRequire } from 'node:module';
86
+ import * as esbuild from 'esbuild';
87
+ import { resolvePlatform } from '../../helpers/cli-flags.js';
88
+ import { getGlobalDefines, getUserDefineEntries } from '../../helpers/global-defines.js';
89
+ @@ -698,6 +699,29 @@ export async function generateDepsBundle(options) {
90
+ // the device cannot resolve.
91
+ const buildPlugins = () => [
92
+ createWebpackLoaderStubEsbuildPlugin(),
93
+ + // Bare `octane` is the DOM entry — a dep importing it (published
94
+ + // @octane-xplat/* dist files kept `from "octane"` through 0.6.0)
95
+ + // bundles a second runtime next to the universal one, and hooks read
96
+ + // an empty CURRENT_SCOPE ("Cannot read properties of null (reading
97
+ + // 'hooks')"). Vite resolve.alias never reaches these esbuild passes;
98
+ + // route exact `octane` imports to the host-neutral entry here.
99
+ + {
100
+ + name: 'ns-deps-bundle-octane-universal-alias',
101
+ + setup(build) {
102
+ + build.onResolve({ filter: /^octane$/ }, (args) => {
103
+ + for (const dir of [args.importer && path.dirname(args.importer), args.resolveDir, projectRoot]) {
104
+ + if (!dir)
105
+ + continue;
106
+ + try {
107
+ + return { path: createRequire(path.join(dir, 'noop.js')).resolve('octane/universal/native') };
108
+ + }
109
+ + catch {
110
+ + }
111
+ + }
112
+ + return null;
113
+ + });
114
+ + },
115
+ + },
116
+ createNodeBuiltinPolyfillEsbuildPlugin(projectRoot, NODE_BUILTINS),
117
+ createNativeClassEsbuildPlugin(platform),
118
+ createVendorEsbuildPlugin(projectRoot),
119
+ diff --git a/hmr/server/device-transform-helpers.js b/hmr/server/device-transform-helpers.js
120
+ index 71574c48f655183af0c9601b020fd1febd63ccb3..0061d9c9e9fe9c6034576eae8449831d19f8ace7 100644
121
+ --- a/hmr/server/device-transform-helpers.js
122
+ +++ b/hmr/server/device-transform-helpers.js
123
+ @@ -79,7 +79,11 @@ function bareSpecifierFromFlatDepPath(depPath) {
124
+ return bareSpecifier;
125
+ }
126
+ function rewriteVitePrebundleImportsForDevice(code, preserveVendorImports) {
127
+ - const imports = collectTopLevelImportRecords(code);
128
+ + // Re-export statements (`export { x } from`/`export * from`) carry specifiers
129
+ + // too — vite's importAnalysis rewrites them to `.vite/deps?v=` URLs the same
130
+ + // as `import` declarations, so they need the same decode. Barrel modules
131
+ + // (e.g. a linked framework package's index) are nothing but re-exports.
132
+ + const imports = collectTopLevelImportRecords(code, true);
133
+ if (!imports.length) {
134
+ return code;
135
+ }
136
+ diff --git a/hmr/server/rewrite-imports.js b/hmr/server/rewrite-imports.js
137
+ index 4a6575cb00a6aeecbbb7ac5ccac3268cb10d7f54..dc70055007e26117b76fbb9d2f4f17fabfd8db00 100644
138
+ --- a/hmr/server/rewrite-imports.js
139
+ +++ b/hmr/server/rewrite-imports.js
140
+ @@ -253,11 +253,29 @@ export function rewriteImports(code, importerPath, sfcFileMap, depFileMap, proje
141
+ }
142
+ return `${prefix}${rewritten}${suffix}`;
143
+ }
144
+ - // Path resolves outside both roots — leave Vite's URL alone as a
145
+ - // last resort. The original behaviour was to fall through here
146
+ - // and let downstream branches (e.g. `normalizeNodeModulesSpecifier`)
147
+ - // handle paths whose abs form happens to contain `/node_modules/`,
148
+ - // so preserve that for the unrewritable case below.
149
+ + // Path resolves outside both roots — the `link:`/`workspace:` case,
150
+ + // where a package's realpath lives in another checkout entirely.
151
+ + // A raw /@fs URL makes the device fetch vite's standard middleware
152
+ + // response, bypassing the device transform: optimizer
153
+ + // `.vite/deps?v=` specifiers inside reach the runtime unrewritten
154
+ + // and 504 once the optimizer re-commits its browserHash. The /ns/m
155
+ + // route already resolves an absolute `/@fs` spec through the full
156
+ + // device pipeline, so route it there. Paths whose realpath still
157
+ + // contains /node_modules/ keep falling through to the bare-package
158
+ + // branch below (upstream behavior).
159
+ + if (!spec.includes('/node_modules/')) {
160
+ + const out = `/ns/m${spec}`;
161
+ + if (httpOriginSafe) {
162
+ + return `${prefix}${httpOriginSafe}${out}${suffix}`;
163
+ + }
164
+ + return `${prefix}${out}${suffix}`;
165
+ + }
166
+ + // Path resolves outside both roots but still names a node_modules
167
+ + // file — leave Vite's URL alone as a last resort. The original
168
+ + // behaviour was to fall through here and let downstream branches
169
+ + // (e.g. `normalizeNodeModulesSpecifier`) handle paths whose abs
170
+ + // form happens to contain `/node_modules/`, so preserve that for
171
+ + // the unrewritable case below.
172
+ }
173
+ // Vite 8 oxc runtime helpers (decorators etc.) — emitted as
174
+ // `/@id/__x00__@oxc-project+runtime@<ver>/helpers/<name>.js`. These are
175
+ diff --git a/hmr/server/websocket-module-specifiers.js b/hmr/server/websocket-module-specifiers.js
176
+ index 74f50a77f48f3873aebf375a29d06b16c29440a3..cc196fb6b92d48179bf8e124ba2a2aa9b13796f9 100644
177
+ --- a/hmr/server/websocket-module-specifiers.js
178
+ +++ b/hmr/server/websocket-module-specifiers.js
179
+ @@ -1,4 +1,4 @@
180
+ -import { existsSync, readdirSync, readFileSync, realpathSync } from 'fs';
181
+ +import { existsSync, readdirSync, readFileSync, realpathSync, statSync } from 'fs';
182
+ import * as path from 'path';
183
+ import * as PAT from './constants.js';
184
+ import { getVendorManifest, resolveVendorSpecifier } from '../shared/vendor/registry.js';
185
+ @@ -328,6 +328,60 @@ export function resolveVendorFromCandidate(specifier) {
186
+ }
187
+ return null;
188
+ }
189
+ +const depFallbackDirsCache = new Map();
190
+ +/**
191
+ + * `node_modules` dirs reachable through the app's dependency specs rather than
192
+ + * its workspace layout — consulted when neither the project root nor the
193
+ + * workspace root can anchor a served `/node_modules/` tail:
194
+ + * - `link:`/`file:`/`portal:` deps keep their own `node_modules` at the real
195
+ + * target; a linked package's transitive deps never reach the app's store.
196
+ + * - pnpm's isolated virtual store keeps every non-hoisted package under
197
+ + * `node_modules/.pnpm/<name>@<ver>/node_modules/`.
198
+ + * Importer info is gone from the URL — first hit wins, same as the workspace
199
+ + * scan above. Cached per project root; the set only changes on install.
200
+ + */
201
+ +function listDepFallbackDirs(projectRoot) {
202
+ + const cached = depFallbackDirsCache.get(projectRoot);
203
+ + if (cached) {
204
+ + return cached;
205
+ + }
206
+ + const dirs = [];
207
+ + const pushIfPresent = (dir) => {
208
+ + if (existsSync(dir))
209
+ + dirs.push(dir);
210
+ + };
211
+ + const pnpmStore = path.join(projectRoot, 'node_modules', '.pnpm');
212
+ + try {
213
+ + for (const entry of readdirSync(pnpmStore, { withFileTypes: true })) {
214
+ + if (entry.isDirectory() && !entry.name.startsWith('.')) {
215
+ + pushIfPresent(path.join(pnpmStore, entry.name, 'node_modules'));
216
+ + }
217
+ + }
218
+ + }
219
+ + catch {
220
+ + }
221
+ + try {
222
+ + const pkg = JSON.parse(readFileSync(path.join(projectRoot, 'package.json'), 'utf8'));
223
+ + for (const section of ['dependencies', 'devDependencies', 'optionalDependencies', 'peerDependencies']) {
224
+ + for (const spec of Object.values(pkg[section] ?? {})) {
225
+ + const target = /^(?:link|file|portal):(.+)$/.exec(String(spec))?.[1];
226
+ + if (!target)
227
+ + continue;
228
+ + try {
229
+ + const depDir = realpathSync(path.resolve(projectRoot, target));
230
+ + if (statSync(depDir).isDirectory())
231
+ + pushIfPresent(path.join(depDir, 'node_modules'));
232
+ + }
233
+ + catch {
234
+ + }
235
+ + }
236
+ + }
237
+ + }
238
+ + catch {
239
+ + }
240
+ + depFallbackDirsCache.set(projectRoot, dirs);
241
+ + return dirs;
242
+ +}
243
+ const workspaceNodeModulesDirsCache = new Map();
244
+ /**
245
+ * `node_modules` dirs that can hold a package the served URL no longer
246
+ @@ -428,6 +482,16 @@ export function resolveCandidateFilePath(candidate, projectRoot, workspaceRoot)
247
+ }
248
+ }
249
+ }
250
+ + // Deps reachable only through the app's dependency specs — linked-package
251
+ + // node_modules, pnpm's virtual store — still resolve to real files.
252
+ + if (cleaned.includes('/node_modules/')) {
253
+ + const tail = cleaned.slice(cleaned.lastIndexOf('/node_modules/') + '/node_modules/'.length);
254
+ + for (const nmDir of listDepFallbackDirs(projectRoot)) {
255
+ + const absPath = path.resolve(nmDir, tail);
256
+ + if (absPath.startsWith(nmDir + path.sep) && existsSync(absPath))
257
+ + return absPath;
258
+ + }
259
+ + }
260
+ return null;
261
+ }
262
+ /**
263
+ @@ -557,22 +621,17 @@ export function filterExistingNodeModulesTransformCandidates(spec, candidates, p
264
+ // through to the existing project/workspace logic.
265
+ }
266
+ if (mapped === null) {
267
+ - if (!hasDistinctWorkspaceRoot) {
268
+ + const relFromProject = path.relative(resolvedProjectRoot, resolved);
269
+ + const insideProjectRoot = relFromProject !== '' && !relFromProject.startsWith('..') && !path.isAbsolute(relFromProject);
270
+ + if (insideProjectRoot) {
271
+ mapped = candidate;
272
+ }
273
+ else {
274
+ - const relFromProject = path.relative(resolvedProjectRoot, resolved);
275
+ - const insideProjectRoot = relFromProject !== '' && !relFromProject.startsWith('..') && !path.isAbsolute(relFromProject);
276
+ - if (insideProjectRoot) {
277
+ - mapped = candidate;
278
+ - }
279
+ - else {
280
+ - // Hoisted `node_modules/<pkg>/...` file lives above projectRoot.
281
+ - // Rewrite the URL to its fs-anchored form so Vite reads it directly
282
+ - // instead of bouncing through bare-specifier resolution that the
283
+ - // hoisted package's `exports` field may refuse.
284
+ - mapped = `/@fs${resolved.replace(/\\/g, '/')}${querySuffix}`;
285
+ - }
286
+ + // File resolves outside the project root — hoisted workspace
287
+ + // node_modules, pnpm's `.pnpm` store, or a link:/file:/portal:
288
+ + // dep's own node_modules. Serve the fs-anchored URL so Vite
289
+ + // reads it directly; the root-relative URL would miss.
290
+ + mapped = `/@fs${resolved.replace(/\\/g, '/')}${querySuffix}`;
291
+ }
292
+ }
293
+ if (seen.has(mapped))
294
+ diff --git a/hmr/server/websocket-ns-m-request.js b/hmr/server/websocket-ns-m-request.js
295
+ index a11fbd5d24579cdf572a91f70cb06561bfa43cd0..c887334efce2c2f6cf85c7508276109467ff3737 100644
296
+ --- a/hmr/server/websocket-ns-m-request.js
297
+ +++ b/hmr/server/websocket-ns-m-request.js
298
+ @@ -27,10 +27,15 @@ const MODULE_CANDIDATE_EXTS = ['ts', 'js', 'tsx', 'jsx', 'mjs', 'mts', 'cts', 'v
299
+ */
300
+ function expandModuleCandidates(spec, hasExt, baseNoExt) {
301
+ const platform = resolvePlatform();
302
+ + // Active platform first, then the remaining platform tags plus the shared
303
+ + // `native` tag split-entry packages use — a plugin shipping only
304
+ + // `index.native.js`, or an `index.android.js` fetched while resolving under
305
+ + // another platform, has no candidate otherwise.
306
+ + const suffixes = [...new Set([platform, 'ios', 'android', 'visionos', 'native'].filter(Boolean))];
307
+ const candidates = hasExt ? [spec] : [];
308
+ for (const base of [baseNoExt, `${baseNoExt}/index`]) {
309
+ - if (platform) {
310
+ - candidates.push(...MODULE_CANDIDATE_EXTS.map((ext) => `${base}.${platform}.${ext}`));
311
+ + for (const suffix of suffixes) {
312
+ + candidates.push(...MODULE_CANDIDATE_EXTS.map((ext) => `${base}.${suffix}.${ext}`));
313
+ }
314
+ candidates.push(...MODULE_CANDIDATE_EXTS.map((ext) => `${base}.${ext}`));
315
+ }
316
+ @@ -149,8 +154,12 @@ export function resolveFsAnchoredSpec(spec, serverRoot, workspaceRoot) {
317
+ for (const root of roots) {
318
+ const rootPosix = root.replace(/\\/g, '/').replace(/\/$/, '');
319
+ const fsId = `/@fs${rootPosix}${spec.startsWith('/') ? '' : '/'}${spec}`;
320
+ - if (resolveCandidateFilePath(fsId, serverRoot, workspaceRoot)) {
321
+ - return fsId;
322
+ + // The fs id is a guess composed under a root — serve the path the
323
+ + // resolver actually found (it may live in a dep's own node_modules,
324
+ + // outside both roots).
325
+ + const resolved = resolveCandidateFilePath(fsId, serverRoot, workspaceRoot);
326
+ + if (resolved) {
327
+ + return `/@fs${resolved.replace(/\\/g, '/')}`;
328
+ }
329
+ }
330
+ return null;
331
+ diff --git a/hmr/server/websocket-served-module-helpers.js b/hmr/server/websocket-served-module-helpers.js
332
+ index b9e3ab67eb4ae7c9b12bc4b02b9aa3660d712644..f857f4a5a5956af229e447ed04bf1a52a90c6399 100644
333
+ --- a/hmr/server/websocket-served-module-helpers.js
334
+ +++ b/hmr/server/websocket-served-module-helpers.js
335
+ @@ -105,8 +105,8 @@ export function classifyServedRequest(spec, resolvedId) {
336
+ return classifyServedModule(spec);
337
+ }
338
+ export const MODULE_IMPORT_ANALYSIS_PLUGINS = ['typescript', 'jsx', 'importMeta', 'topLevelAwait', 'classProperties', 'classPrivateProperties', 'classPrivateMethods', 'decorators-legacy'];
339
+ -export function collectTopLevelImportRecords(code) {
340
+ - if (!code || typeof code !== 'string' || !/\bimport\b/.test(code)) {
341
+ +export function collectTopLevelImportRecords(code, includeReExports = false) {
342
+ + if (!code || typeof code !== 'string' || !(includeReExports ? /\b(?:import|export)\b/ : /\bimport\b/).test(code)) {
343
+ return [];
344
+ }
345
+ try {
346
+ @@ -119,7 +119,7 @@ export function collectTopLevelImportRecords(code) {
347
+ return [];
348
+ }
349
+ return body
350
+ - .filter((node) => t.isImportDeclaration(node) && typeof node.start === 'number' && typeof node.end === 'number' && typeof node.source?.value === 'string')
351
+ + .filter((node) => (t.isImportDeclaration(node) || (includeReExports && (t.isExportNamedDeclaration(node) || t.isExportAllDeclaration(node)))) && typeof node.start === 'number' && typeof node.end === 'number' && typeof node.source?.value === 'string')
352
+ .map((node) => ({
353
+ start: node.start,
354
+ end: node.end,
@@ -0,0 +1,78 @@
1
+ diff --git a/src/Context.tsrx b/src/Context.tsrx
2
+ index fd5ced72b3ac2e789c3feea4aff73c7c41645c26..92174f36f5e58bef6e7ec0785f7241918cd1a6ee 100644
3
+ --- a/src/Context.tsrx
4
+ +++ b/src/Context.tsrx
5
+ @@ -3,10 +3,24 @@
6
+ // render-prop contract with useContext instead.
7
+ import { isChildrenBlock, useMemo, type OctaneNode } from 'octane';
8
+
9
+ -import { EditorContext, useCurrentEditor, type EditorContextValue } from './Context';
10
+ import { EditorContent, type EditorContentProps } from './EditorContent.tsrx';
11
+ import { useEditor, type UseEditorOptions } from './useEditor';
12
+
13
+ +import type { Editor } from '@tiptap/core';
14
+ +import { createContext, useContext } from 'octane';
15
+ +
16
+ +export type EditorContextValue = {
17
+ + editor: Editor | null;
18
+ +};
19
+ +
20
+ +export const EditorContext = createContext<EditorContextValue>({
21
+ + editor: null,
22
+ +});
23
+ +
24
+ +export function useCurrentEditor(): EditorContextValue {
25
+ + return useContext(EditorContext);
26
+ +}
27
+ +
28
+ export interface EditorConsumerProps {
29
+ children: (value: EditorContextValue) => OctaneNode;
30
+ }
31
+ diff --git a/src/Context.tsrx.d.ts b/src/Context.tsrx.d.ts
32
+ index 96c24a2bd79e19fd67532bc92b6f31976f575f95..c99a289a9443251e18552e0c878a204bbbcb6b48 100644
33
+ --- a/src/Context.tsrx.d.ts
34
+ +++ b/src/Context.tsrx.d.ts
35
+ @@ -2,9 +2,16 @@ import type { OctaneNode } from 'octane';
36
+ import type { Octane } from 'octane/jsx-runtime';
37
+
38
+ import type { EditorContentProps } from './EditorContent.tsrx';
39
+ -import type { EditorContextValue } from './Context';
40
+ +import type { EditorContextValue } from './Context.ts';
41
+ import type { UseEditorOptions } from './useEditor';
42
+
43
+ +import type { Editor } from '@tiptap/core';
44
+ +import type { Context } from 'octane';
45
+ +
46
+ +export declare const EditorContext: Context<EditorContextValue>;
47
+ +export declare function useCurrentEditor(): EditorContextValue;
48
+ +export type { EditorContextValue };
49
+ +
50
+ export interface EditorConsumerProps {
51
+ children: (value: EditorContextValue) => OctaneNode;
52
+ }
53
+ diff --git a/src/useEditor.ts b/src/useEditor.ts
54
+ index c30a55e3889a8dfdd6614a6f03422180bcf3116d..339921dc4c7ce32d7bc56dd5d66615aec682d8de 100644
55
+ --- a/src/useEditor.ts
56
+ +++ b/src/useEditor.ts
57
+ @@ -7,7 +7,8 @@ import { useEditorState, type UseEditorStateOptions } from './useEditorState';
58
+ type DependencyList = readonly unknown[];
59
+ type MutableRefObject<T> = { current: T };
60
+
61
+ -const isDev = process.env.NODE_ENV !== 'production';
62
+ +declare const process: { env: { NODE_ENV?: string } };
63
+ +const isDev = process.env.NODE_ENV !== 'production';
64
+ const isSSR = typeof window === 'undefined';
65
+ const isNext = isSSR || Boolean(typeof window !== 'undefined' && (window as any).next);
66
+
67
+ diff --git a/src/index.ts b/src/index.ts
68
+ --- a/src/index.ts
69
+ +++ b/src/index.ts
70
+ @@ -1,6 +1,7 @@
71
+ 'use client';
72
+
73
+ -export * from './Context';
74
+ +// './Context' resolves to Context.tsrx under suffix-first resolution — the
75
+ +// star-export on the next line already covers it, so this is a duplicate.
76
+ export * from './Context.tsrx';
77
+ export * from './EditorContent.tsrx';
78
+ export * from './NodeViewContent';
@@ -0,0 +1,11 @@
1
+ diff --git a/dist/language-CofXAudP.js b/dist/language-CofXAudP.js
2
+ index 0d5504342813cd32b77bc834f9ed01bf6a353e3f..aff65966aba619c96f627474bb8e36c34d44f3e1 100644
3
+ --- a/dist/language-CofXAudP.js
4
+ +++ b/dist/language-CofXAudP.js
5
+ @@ -3,5 +3,5 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
6
+ `));return e?null:void 0}let u=D(o.layers,e=>ne(e.config));if(u.state===`invalid`)return j(`Invalid TSRX ${u.target} declaration:`,u.actual_type,u.actual_value,`in ${u.config_path}`),null;let f=o.extends_failures.filter(e=>u.state!==`declared`||!B(o.layers,e,u.config_path));if(f.length>0){for(let e of f){if(e.diagnostics.length===0){j(`Unable to resolve tsconfig extends entry:`,JSON.stringify(e.extends_value),`in ${e.config_path}`);continue}for(let t of e.diagnostics)j(`Unable to resolve tsconfig extends entry:`,JSON.stringify(e.extends_value),`in ${e.config_path}`,n.flattenDiagnosticMessageText(t.messageText,`
7
+ `))}return null}if(u.state===`declared`)return ae(n,r,u.config_path,u.value)}function se(e,t={}){let n=t.ts??l.default,r=t.configHost??n.sys,i=I(r),a=t.configFileName??R(d.default.dirname(e),r,i);if(a===null)return;let o=z(n,r,a,i);for(let e of o.dependencies)t.dependencies?.add(e);let s=o.layers.find(e=>e.raw_source===void 0);if(s){let e=`Unable to read tsconfig layer while resolving TSRX platform: ${s.path}`;throw j(e),Error(e)}let c=o.layers.filter(e=>e.parse_diagnostics.length>0);if(c.length>0){if(!o.layers.some(e=>E(e.config,[`tsrx`]).state===`found`?!0:e.parse_diagnostics.length>0&&e.raw_source!==void 0&&M.test(e.raw_source)))return;let e=c[0],t=n.flattenDiagnosticMessageText(e.parse_diagnostics[0].messageText,`
8
+ `),r=`Unable to parse tsconfig layer while resolving TSRX platform: ${e.path}: ${t}`;throw j(r),Error(r)}let u=D(o.layers,e=>re(e.config));if(u.state===`invalid`){let e=u.target===`platform`?` Expected "web", "ios", or "android".`:``,t=`Invalid TSRX ${u.target} declaration: ${u.actual_type} ${u.actual_value} in ${u.config_path}.${e}`;throw j(t),TypeError(t)}let f=o.extends_failures.filter(e=>u.state!==`declared`||!B(o.layers,e,u.config_path));if(f.length>0){if(!t.requirePlatformResolution)return u.state===`declared`?u.value:void 0;let e=f[0],r=e.diagnostics.length>0?`: ${n.flattenDiagnosticMessageText(e.diagnostics[0].messageText,`
9
+ -`)}`:``,i=`Unable to resolve tsconfig extends entry ${JSON.stringify(e.extends_value)} in ${e.config_path} while resolving TSRX platform${r}`;throw j(i),Error(i)}return u.state===`declared`?u.value:void 0}const ce=(0,f.createRequire)(require(`url`).pathToFileURL(__filename).href),le=d.default.dirname((0,p.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),{log:V,logWarning:H,logError:U}=k(`[TSRX Language]`),W=new Set,G=[`.tsrx`],K=[[`@tsrx/ripple`,[`node_modules`,`@tsrx`,`ripple`],[`.tsrx`],[`@tsrx/ripple`,`ripple`,`@ripple-ts/vite-plugin`]],[`@tsrx/react`,[`node_modules`,`@tsrx`,`react`],[`.tsrx`],[`@tsrx/react`,`@tsrx/vite-plugin-react`]],[`@tsrx/solid`,[`node_modules`,`@tsrx`,`solid`],[`.tsrx`],[`@tsrx/solid`,`@tsrx/vite-plugin-solid`]],[`@tsrx/preact`,[`node_modules`,`@tsrx`,`preact`],[`.tsrx`],[`@tsrx/preact`,`@tsrx/vite-plugin-preact`]],[`@tsrx/vue`,[`node_modules`,`@tsrx`,`vue`],[`.tsrx`],[`@tsrx/vue`,`@tsrx/vite-plugin-vue`]],[`@tsrx/hono`,[`node_modules`,`@tsrx`,`hono`],[`.tsrx`],[`@tsrx/hono`,`@tsrx/vite-plugin-hono`]],[`octane`,[`node_modules`,`octane`],[`.tsrx`],[`octane`,`@octanejs/vite-plugin`],[[`dist`,`compiler`,`volar.js`],[`src`,`compiler`,`volar.js`]]]],ue=[[`src`,`index.js`]];function de(e){return G.some(t=>e.endsWith(t))}function fe(e,t=l.default){let n=t.createScanner(t.ScriptTarget.Latest,!0,t.LanguageVariant.JSX,e),r=[];for(let e=n.scan();e!==t.SyntaxKind.EndOfFileToken;e=n.scan())r.push({kind:e,text:n.getTokenText()});let i=[`import`,`.`,`meta`,`.`,`env`,`.`,`platform`,`.`];for(let e=0;e+i.length<r.length;e+=1){if(e>0&&(r[e-1].kind===t.SyntaxKind.DotToken||r[e-1].kind===t.SyntaxKind.QuestionDotToken)||!i.every((t,n)=>r[e+n].text===t))continue;let n=r[e+i.length].text;if(n===`web`||n===`ios`||n===`android`)return!0}return!1}function pe(e={}){V(`Creating TSRX language plugin...`);let t=e.ts??l.default,n={...e,ts:t,configHost:e.configHost??t.sys};return{getLanguageId(e){let t=typeof e==`string`?e:e.fsPath.replace(/\\/g,`/`);if(de(t))return V(`Identified TSRX file:`,t),`tsrx`},createVirtualCode(e,t,r){if(t===`tsrx`){let t=ve(e),i=ye(t,n);if(!i){U(`TSRX compiler not found for file: ${t}`);return}V(`Creating virtual code for:`,t);try{return new q(t,r,i,e=>se(t,{...n,requirePlatformResolution:e}))}catch(e){throw U(`Failed to create virtual code for:`,t,`:`,e),e}}},updateVirtualCode(e,t,n){if(t instanceof q)return V(`Updating existing virtual code for:`,t.fileName),t.update(n),t},typescript:{extraFileExtensions:G.map(e=>({extension:e.slice(1),isMixedContent:!1,scriptKind:7})),getServiceScript(e){for(let t of(0,w.forEachEmbeddedCode)(e))if(t.languageId===`tsrx`)return{code:t,extension:`.tsx`,scriptKind:4}},...process.env.TSRX_TSC===`true`?null:{getExtraServiceScripts(e,t){let n=[];for(let r of(0,w.forEachEmbeddedCode)(t))r.languageId===`typescript`&&n.push({fileName:`${e}.${r.id}.ts`,code:r,extension:`.ts`,scriptKind:l.default.ScriptKind.TS});return n}}}}}var q=class{id=`root`;languageId=`tsrx`;codegenStacks=[];tsrx;platformProvider;generatedCode=``;embeddedCodes=[];mappings=[];fatalErrors=[];usageErrors=[];snapshot;sourceSnapshot;originalCode=``;sourceAst=null;isDotCompletionMode=!1;diagnostics=[];#e=null;#t=null;constructor(e,t,n,r){if(V(`Initializing TSRXVirtualCode for:`,e),this.fileName=e,this.tsrx=n,this.platformProvider=r,this.snapshot=t,this.sourceSnapshot=t,this.originalCode=t.getText(0,t.getLength()),!n||typeof n.compile_to_volar_mappings!=`function`)throw U(`Invalid TSRX compiler - missing compile_to_volar_mappings method`),Error(`Invalid TSRX compiler`);this.update(t)}update(e){V(`Updating virtual code for:`,this.fileName);let t=e.getText(0,e.getLength()),n=e.getChangeRange(this.sourceSnapshot);this.sourceSnapshot=e,this.#e=null,this.#t=null,this.fatalErrors=[],this.usageErrors=[],this.sourceAst=null,this.isDotCompletionMode=!1;let r,i=!1,a=-1;if(V(`changeRange:`,JSON.stringify(n)),n){let e=n.span.start,r=e+n.span.length,o=e+n.newLength,s=this.originalCode.substring(e,r),c=t.substring(e,o);if(V(`Change details:`),V(` Position:`,e,`-`,r,`(length:`,n.span.length,`)`),V(` Old text:`,JSON.stringify(s)),V(` New text:`,JSON.stringify(c),`(length:`,n.newLength,`)`),c.endsWith(`.`)){let e=o>1?t[o-2]:``;V(` Char before dot:`,JSON.stringify(e)),/[$#_\u200C\u200D\p{ID_Continue}\)\]\}]/u.test(e)&&(i=!0,a=o-1,V(`ChangeRange detected dot typed at position`,a))}}try{let e=this.platformProvider?.(fe(t));if(i&&a>=0){this.isDotCompletionMode=!0;let n=t.substring(0,a)+t.substring(a+1);if(V(`Compiling without typed dot at position`,a),r=this.tsrx.compile_to_volar_mappings(n,this.fileName,{loose:!0,platform:e}),V(`Compilation without dot successful`),r&&r.code&&r.mappings.length>0){let e=ge(r,a);e===null?H(`Failed to restore typed dot into transpiled output`):V(`Inserted typed dot at generated position`,e)}}else V(`Compiling TSRX code...`),r=this.tsrx.compile_to_volar_mappings(t,this.fileName,{loose:!0,platform:e}),V(`Compilation successful, generated code length:`,r?.code?.length||0)}catch(e){let t=e;U(`TSRX compilation failed for`,this.fileName,`:`,t),process.env.TSRX_TSC===`true`&&Y(this.fileName,[t]),t.type=`fatal`,this.fatalErrors.push(t)}if(r&&r.code){this.originalCode=t,this.generatedCode=r.code,this.mappings=r.mappings??[],this.usageErrors=r.errors,this.sourceAst=r.sourceAst,process.env.TSRX_TSC===`true`&&r.errors.length>0&&Y(this.fileName,r.errors);let e=r.cssMappings,n=r.scriptMappings??[];if(e.length>0||n.length>0){V(`Creating`,e.length,`CSS and`,n.length,`script embedded codes`);let t=[];for(let n of e)t.push(X(n,`css`));for(let e of n)t.push(X(e,`typescript`));this.embeddedCodes=t}else this.embeddedCodes=[];if(O){V(`CSS embedded codes:`,(this.embeddedCodes||[]).length),V(`Using transpiled code, mapping count:`,this.mappings.length),V(`Original code length:`,t.length),V(`Generated code length:`,this.generatedCode.length),V(`Last 100 chars of original:`,JSON.stringify(t.slice(-100))),V(`Last 200 chars of generated:`,JSON.stringify(this.generatedCode.slice(-200))),V(`Last few mappings:`);let e=Math.max(0,this.mappings.length-5);for(let t=e;t<this.mappings.length;t++){let e=this.mappings[t];V(` Mapping ${t}: source[${e.sourceOffsets[0]}:${e.sourceOffsets[0]+e.lengths[0]}] -> gen[${e.generatedOffsets[0]}:${e.generatedOffsets[0]+e.lengths[0]}], len=${e.lengths[0]}, completion=${e.data?.completion}`)}}this.snapshot={getText:(e,t)=>this.generatedCode.substring(e,t),getLength:()=>this.generatedCode.length,getChangeRange:()=>void 0}}else V(`Compilation failed, only display where the compilation error occurred.`),this.originalCode=t,this.generatedCode=t,this.mappings=[{sourceOffsets:[0],generatedOffsets:[0],lengths:[t.length],generatedLengths:[t.length],data:{completion:!0,verification:!0,customData:{}}}],this.embeddedCodes=[...me(t),...he(t)],this.snapshot={getText:(e,t)=>this.generatedCode.substring(e,t),getLength:()=>this.generatedCode.length,getChangeRange:()=>void 0}}#n(){if(!(this.#e||this.#t)){this.#e=new Map,this.#t=new Map;for(var e,t,n,r,i,a,o,s,c,l=0;l<this.mappings.length;l++)e=this.mappings[l],t=e.generatedOffsets[0],n=e.generatedLengths[0],r=t+n,i=`${t}-${r}`,this.#e.set(i,e),a=e.sourceOffsets[0],o=e.lengths[0],s=a+o,c=`${a}-${s}`,this.#t.set(c,e)}}findMappingByGeneratedRange(e,t){return this.#n(),this.#e.get(`${e}-${t}`)??null}findMappingBySourceRange(e,t){return this.#n(),this.#t.get(`${e}-${t}`)??null}findGeneratedRangeBySourceRange(e,t){let n=null,r=null;for(let i=0;i<this.mappings.length;i++){let a=this.mappings[i],o=a.sourceOffsets[0],s=o+a.lengths[0];s<=e||o>=t||((!n||o<n.sourceOffsets[0])&&(n=a),(!r||s>r.sourceOffsets[0]+r.lengths[0])&&(r=a))}if(!n||!r)return null;let i=n.generatedOffsets[0]+J(e-n.sourceOffsets[0],n.generatedLengths[0]),a=r.generatedOffsets[0]+J(t-r.sourceOffsets[0],r.generatedLengths[0]);return[i,Math.max(a,i+1)]}};function J(e,t){return Math.min(Math.max(e,0),t)}function Y(e,t){for(let n of t){let t=n&&typeof n==`object`&&`message`in n?String(n.message):String(n),r=`${e}\0${t}`;W.has(r)||(W.add(r),console.error(`[tsrx-tsc] ${e}: ${t}`))}}function me(e){let t=[],n=/<style\b((?:[^>"'{}/]|"[^"]*"|'[^']*'|\{(?:[^{}]|\{[^{}]*\})*\}|\/(?!>))*)>([\s\S]*?)<\/style>/gi,r,i=0;for(;(r=n.exec(e))!==null;){let e=r[1],n=r[2],a=r.index+(6+e.length+1),o=n.length,s=`style_${i}`;V(`Extracted CSS region ${i}: offset ${a}, length ${o}`);let c={sourceOffsets:[a],generatedOffsets:[0],lengths:[o],generatedLengths:[o],data:{verification:!0,completion:!0,semantic:!0,navigation:!0,structure:!0,format:!1,customData:{content:n,embeddedId:s}}};t.push(X(c,`css`)),i++}return t.length>0&&V(`Extracted ${t.length} CSS embedded codes from style tags`),t}function X(e,t){let n=e.data?.customData?.content??``;return{id:e.data?.customData?.embeddedId,languageId:t,snapshot:{getText:(e,t)=>n.substring(e,t),getLength:()=>e.lengths[0],getChangeRange:()=>void 0},mappings:[e],embeddedCodes:[]}}function he(e){let t=[],n=/<script\b((?:[^>"'/]|"[^"]*"|'[^']*'|\/(?!>))*)>([\s\S]*?)<\/script>/gi,r,i=0;for(;(r=n.exec(e))!==null;){let e=r[1],n=r[2],a=r.index+(7+e.length+1),o=n.length,s=`script_${i}`;V(`Extracted script region ${i}: offset ${a}, length ${o}`);let c={sourceOffsets:[a],generatedOffsets:[0],lengths:[o],generatedLengths:[o],data:{verification:!0,completion:!0,semantic:!0,navigation:!0,structure:!0,format:!1,customData:{content:n,embeddedId:s}}};t.push(X(c,`typescript`)),i++}return t.length>0&&V(`Extracted ${t.length} script embedded codes from script tags`),t}function ge(e,t){let n=null;for(let r of e.mappings)if(r.sourceOffsets[0]+r.lengths[0]===t){n=r;break}if(!n)return null;let r=n.generatedLengths[0],i=n.generatedOffsets[0]+r;e.code=e.code.substring(0,i)+`.`+e.code.substring(i);let a={sourceOffsets:[t],generatedOffsets:[i],lengths:[1],generatedLengths:[1],data:{...n.data}},o=e.mappings.indexOf(n);e.mappings.splice(o+1,0,a);for(let r of e.mappings)r!==n&&r!==a&&r.generatedOffsets[0]>=i&&(r.generatedOffsets[0]+=1),r!==n&&r!==a&&r.sourceOffsets[0]>=t&&(r.sourceOffsets[0]+=1);return i}const _e=new Map,Z=new Map;function ve(e){return typeof e==`string`?e:e.fsPath.replace(/\\/g,`/`)}function Q(e,t=u.default.existsSync){let n=e,r=[];for(;n;){if(Z.has(n)){let e=Z.get(n)??null;for(let t of r)Z.set(t,e);return e}r.push(n);let e=d.default.join(n,`package.json`);if(t(e))try{let t=JSON.parse(u.default.readFileSync(e,`utf8`)),n=new Set([...Object.keys(t.dependencies??{}),...Object.keys(t.devDependencies??{}),...Object.keys(t.peerDependencies??{}),...Object.keys(t.optionalDependencies??{})]),i={name:typeof t.name==`string`?t.name:null,dependencies:n};for(let e of r)Z.set(e,i);return i}catch{for(let e of r)Z.set(e,null);return null}let i=d.default.dirname(n);if(i===n)break;n=i}for(let e of r)Z.set(e,null);return null}function $(e,t,n){if(!e)return!1;if(e.name===t||n.includes(e.name??``)||e.dependencies.has(t))return!0;for(let t of n)if(e.dependencies.has(t))return!0;return!1}function ye(e,t){let n=Se(e,t);if(n)return be(ce(n))}function be(e){return typeof e?.compile_to_volar_mappings!=`function`&&typeof e?.compileToVolarMappings==`function`?{...e,compile_to_volar_mappings:e.compileToVolarMappings}:e}function xe(e,t=u.default.existsSync,n=_e){let r=e.split(`/`),i=d.default.extname(e);for(let e=r.length-2;e>=0;e--){let a=r.slice(0,e+1).join(`/`),o=a+`\0`+i;if(!n.has(o)){let e=[];for(let[n,r,o,s,c=ue]of K)if(o.includes(i))for(let i of c){let o=[a,...r,...i].join(`/`);if(t(o)){e.push([n,o,s]);break}}let r=null;if(e.length>0){let n=Q(a,t);r=e.find(([e,,t])=>$(n,e,t))?.[1]??e[0][1],V(`Found tsrx compiler at:`,r,`for extension:`,i)}n.set(o,r)}let s=n.get(o);if(s)return s}}function Se(e,t){let n=d.default.extname(e),r=oe(e,t);if(r!==void 0)return r??void 0;let i=Q(d.default.dirname(e)),a=xe(e);if(a)return a;let o=`No supported tsrx compiler found in workspace for ${e}.`,s=le;for(;s;){let e=[];for(let[t,r,i,a,o=ue]of K){if(!i.includes(n))continue;let c=d.default.join(s,...r);for(let n of o){let r=d.default.join(c,...n);if(u.default.existsSync(r)){e.push([t,r,a]);break}}}if(e.length>0){let t=e.find(([e,,t])=>$(i,e,t))?.[1]??e[0][1];return H(`${o} Using packaged version at ${t}`),t}let t=d.default.dirname(s);if(t===s)break;s=t}}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return pe}});
10
+ +`)}`:``,i=`Unable to resolve tsconfig extends entry ${JSON.stringify(e.extends_value)} in ${e.config_path} while resolving TSRX platform${r}`;throw j(i),Error(i)}return u.state===`declared`?u.value:void 0}const ce=(0,f.createRequire)(require(`url`).pathToFileURL(__filename).href),le=d.default.dirname((0,p.fileURLToPath)(require(`url`).pathToFileURL(__filename).href)),{log:V,logWarning:H,logError:U}=k(`[TSRX Language]`),W=new Set,G=[`.tsrx`],K=[[`@tsrx/ripple`,[`node_modules`,`@tsrx`,`ripple`],[`.tsrx`],[`@tsrx/ripple`,`ripple`,`@ripple-ts/vite-plugin`]],[`@tsrx/react`,[`node_modules`,`@tsrx`,`react`],[`.tsrx`],[`@tsrx/react`,`@tsrx/vite-plugin-react`]],[`@tsrx/solid`,[`node_modules`,`@tsrx`,`solid`],[`.tsrx`],[`@tsrx/solid`,`@tsrx/vite-plugin-solid`]],[`@tsrx/preact`,[`node_modules`,`@tsrx`,`preact`],[`.tsrx`],[`@tsrx/preact`,`@tsrx/vite-plugin-preact`]],[`@tsrx/vue`,[`node_modules`,`@tsrx`,`vue`],[`.tsrx`],[`@tsrx/vue`,`@tsrx/vite-plugin-vue`]],[`@tsrx/hono`,[`node_modules`,`@tsrx`,`hono`],[`.tsrx`],[`@tsrx/hono`,`@tsrx/vite-plugin-hono`]],[`octane`,[`node_modules`,`octane`],[`.tsrx`],[`octane`,`@octanejs/vite-plugin`],[[`dist`,`compiler`,`volar.js`],[`src`,`compiler`,`volar.js`]]]],ue=[[`src`,`index.js`]];function de(e){return G.some(t=>e.endsWith(t))}function fe(e,t=l.default){let n=t.createScanner(t.ScriptTarget.Latest,!0,t.LanguageVariant.JSX,e),r=[];for(let e=n.scan();e!==t.SyntaxKind.EndOfFileToken;e=n.scan())r.push({kind:e,text:n.getTokenText()});let i=[`import`,`.`,`meta`,`.`,`env`,`.`,`platform`,`.`];for(let e=0;e+i.length<r.length;e+=1){if(e>0&&(r[e-1].kind===t.SyntaxKind.DotToken||r[e-1].kind===t.SyntaxKind.QuestionDotToken)||!i.every((t,n)=>r[e+n].text===t))continue;let n=r[e+i.length].text;if(n===`web`||n===`ios`||n===`android`)return!0}return!1}function pe(e={}){V(`Creating TSRX language plugin...`);let t=e.ts??l.default,n={...e,ts:t,configHost:e.configHost??t.sys};return{getLanguageId(e){let t=typeof e==`string`?e:e.fsPath.replace(/\\/g,`/`);if(de(t))return V(`Identified TSRX file:`,t),`tsrx`},createVirtualCode(e,t,r){if(t===`tsrx`){let t=ve(e),i=ye(t,n);if(!i){U(`TSRX compiler not found for file: ${t}`);return}V(`Creating virtual code for:`,t);try{return new q(t,r,i,e=>se(t,{...n,requirePlatformResolution:e}))}catch(e){throw U(`Failed to create virtual code for:`,t,`:`,e),e}}},updateVirtualCode(e,t,n){if(t instanceof q)return V(`Updating existing virtual code for:`,t.fileName),t.update(n),t},typescript:{resolveHiddenExtensions:!0,extraFileExtensions:G.map(e=>({extension:e.slice(1),isMixedContent:!1,scriptKind:7})),getServiceScript(e){for(let t of(0,w.forEachEmbeddedCode)(e))if(t.languageId===`tsrx`)return{code:t,extension:`.tsx`,scriptKind:4}},...process.env.TSRX_TSC===`true`?null:{getExtraServiceScripts(e,t){let n=[];for(let r of(0,w.forEachEmbeddedCode)(t))r.languageId===`typescript`&&n.push({fileName:`${e}.${r.id}.ts`,code:r,extension:`.ts`,scriptKind:l.default.ScriptKind.TS});return n}}}}}var q=class{id=`root`;languageId=`tsrx`;codegenStacks=[];tsrx;platformProvider;generatedCode=``;embeddedCodes=[];mappings=[];fatalErrors=[];usageErrors=[];snapshot;sourceSnapshot;originalCode=``;sourceAst=null;isDotCompletionMode=!1;diagnostics=[];#e=null;#t=null;constructor(e,t,n,r){if(V(`Initializing TSRXVirtualCode for:`,e),this.fileName=e,this.tsrx=n,this.platformProvider=r,this.snapshot=t,this.sourceSnapshot=t,this.originalCode=t.getText(0,t.getLength()),!n||typeof n.compile_to_volar_mappings!=`function`)throw U(`Invalid TSRX compiler - missing compile_to_volar_mappings method`),Error(`Invalid TSRX compiler`);this.update(t)}update(e){V(`Updating virtual code for:`,this.fileName);let t=e.getText(0,e.getLength()),n=e.getChangeRange(this.sourceSnapshot);this.sourceSnapshot=e,this.#e=null,this.#t=null,this.fatalErrors=[],this.usageErrors=[],this.sourceAst=null,this.isDotCompletionMode=!1;let r,i=!1,a=-1;if(V(`changeRange:`,JSON.stringify(n)),n){let e=n.span.start,r=e+n.span.length,o=e+n.newLength,s=this.originalCode.substring(e,r),c=t.substring(e,o);if(V(`Change details:`),V(` Position:`,e,`-`,r,`(length:`,n.span.length,`)`),V(` Old text:`,JSON.stringify(s)),V(` New text:`,JSON.stringify(c),`(length:`,n.newLength,`)`),c.endsWith(`.`)){let e=o>1?t[o-2]:``;V(` Char before dot:`,JSON.stringify(e)),/[$#_\u200C\u200D\p{ID_Continue}\)\]\}]/u.test(e)&&(i=!0,a=o-1,V(`ChangeRange detected dot typed at position`,a))}}try{let e=this.platformProvider?.(fe(t));if(i&&a>=0){this.isDotCompletionMode=!0;let n=t.substring(0,a)+t.substring(a+1);if(V(`Compiling without typed dot at position`,a),r=this.tsrx.compile_to_volar_mappings(n,this.fileName,{loose:!0,platform:e}),V(`Compilation without dot successful`),r&&r.code&&r.mappings.length>0){let e=ge(r,a);e===null?H(`Failed to restore typed dot into transpiled output`):V(`Inserted typed dot at generated position`,e)}}else V(`Compiling TSRX code...`),r=this.tsrx.compile_to_volar_mappings(t,this.fileName,{loose:!0,platform:e}),V(`Compilation successful, generated code length:`,r?.code?.length||0)}catch(e){let t=e;U(`TSRX compilation failed for`,this.fileName,`:`,t),process.env.TSRX_TSC===`true`&&Y(this.fileName,[t]),t.type=`fatal`,this.fatalErrors.push(t)}if(r&&r.code){this.originalCode=t,this.generatedCode=r.code,this.mappings=r.mappings??[],this.usageErrors=r.errors,this.sourceAst=r.sourceAst,process.env.TSRX_TSC===`true`&&r.errors.length>0&&Y(this.fileName,r.errors);let e=r.cssMappings,n=r.scriptMappings??[];if(e.length>0||n.length>0){V(`Creating`,e.length,`CSS and`,n.length,`script embedded codes`);let t=[];for(let n of e)t.push(X(n,`css`));for(let e of n)t.push(X(e,`typescript`));this.embeddedCodes=t}else this.embeddedCodes=[];if(O){V(`CSS embedded codes:`,(this.embeddedCodes||[]).length),V(`Using transpiled code, mapping count:`,this.mappings.length),V(`Original code length:`,t.length),V(`Generated code length:`,this.generatedCode.length),V(`Last 100 chars of original:`,JSON.stringify(t.slice(-100))),V(`Last 200 chars of generated:`,JSON.stringify(this.generatedCode.slice(-200))),V(`Last few mappings:`);let e=Math.max(0,this.mappings.length-5);for(let t=e;t<this.mappings.length;t++){let e=this.mappings[t];V(` Mapping ${t}: source[${e.sourceOffsets[0]}:${e.sourceOffsets[0]+e.lengths[0]}] -> gen[${e.generatedOffsets[0]}:${e.generatedOffsets[0]+e.lengths[0]}], len=${e.lengths[0]}, completion=${e.data?.completion}`)}}this.snapshot={getText:(e,t)=>this.generatedCode.substring(e,t),getLength:()=>this.generatedCode.length,getChangeRange:()=>void 0}}else V(`Compilation failed, only display where the compilation error occurred.`),this.originalCode=t,this.generatedCode=t,this.mappings=[{sourceOffsets:[0],generatedOffsets:[0],lengths:[t.length],generatedLengths:[t.length],data:{completion:!0,verification:!0,customData:{}}}],this.embeddedCodes=[...me(t),...he(t)],this.snapshot={getText:(e,t)=>this.generatedCode.substring(e,t),getLength:()=>this.generatedCode.length,getChangeRange:()=>void 0}}#n(){if(!(this.#e||this.#t)){this.#e=new Map,this.#t=new Map;for(var e,t,n,r,i,a,o,s,c,l=0;l<this.mappings.length;l++)e=this.mappings[l],t=e.generatedOffsets[0],n=e.generatedLengths[0],r=t+n,i=`${t}-${r}`,this.#e.set(i,e),a=e.sourceOffsets[0],o=e.lengths[0],s=a+o,c=`${a}-${s}`,this.#t.set(c,e)}}findMappingByGeneratedRange(e,t){return this.#n(),this.#e.get(`${e}-${t}`)??null}findMappingBySourceRange(e,t){return this.#n(),this.#t.get(`${e}-${t}`)??null}findGeneratedRangeBySourceRange(e,t){let n=null,r=null;for(let i=0;i<this.mappings.length;i++){let a=this.mappings[i],o=a.sourceOffsets[0],s=o+a.lengths[0];s<=e||o>=t||((!n||o<n.sourceOffsets[0])&&(n=a),(!r||s>r.sourceOffsets[0]+r.lengths[0])&&(r=a))}if(!n||!r)return null;let i=n.generatedOffsets[0]+J(e-n.sourceOffsets[0],n.generatedLengths[0]),a=r.generatedOffsets[0]+J(t-r.sourceOffsets[0],r.generatedLengths[0]);return[i,Math.max(a,i+1)]}};function J(e,t){return Math.min(Math.max(e,0),t)}function Y(e,t){for(let n of t){let t=n&&typeof n==`object`&&`message`in n?String(n.message):String(n),r=`${e}\0${t}`;W.has(r)||(W.add(r),console.error(`[tsrx-tsc] ${e}: ${t}`))}}function me(e){let t=[],n=/<style\b((?:[^>"'{}/]|"[^"]*"|'[^']*'|\{(?:[^{}]|\{[^{}]*\})*\}|\/(?!>))*)>([\s\S]*?)<\/style>/gi,r,i=0;for(;(r=n.exec(e))!==null;){let e=r[1],n=r[2],a=r.index+(6+e.length+1),o=n.length,s=`style_${i}`;V(`Extracted CSS region ${i}: offset ${a}, length ${o}`);let c={sourceOffsets:[a],generatedOffsets:[0],lengths:[o],generatedLengths:[o],data:{verification:!0,completion:!0,semantic:!0,navigation:!0,structure:!0,format:!1,customData:{content:n,embeddedId:s}}};t.push(X(c,`css`)),i++}return t.length>0&&V(`Extracted ${t.length} CSS embedded codes from style tags`),t}function X(e,t){let n=e.data?.customData?.content??``;return{id:e.data?.customData?.embeddedId,languageId:t,snapshot:{getText:(e,t)=>n.substring(e,t),getLength:()=>e.lengths[0],getChangeRange:()=>void 0},mappings:[e],embeddedCodes:[]}}function he(e){let t=[],n=/<script\b((?:[^>"'/]|"[^"]*"|'[^']*'|\/(?!>))*)>([\s\S]*?)<\/script>/gi,r,i=0;for(;(r=n.exec(e))!==null;){let e=r[1],n=r[2],a=r.index+(7+e.length+1),o=n.length,s=`script_${i}`;V(`Extracted script region ${i}: offset ${a}, length ${o}`);let c={sourceOffsets:[a],generatedOffsets:[0],lengths:[o],generatedLengths:[o],data:{verification:!0,completion:!0,semantic:!0,navigation:!0,structure:!0,format:!1,customData:{content:n,embeddedId:s}}};t.push(X(c,`typescript`)),i++}return t.length>0&&V(`Extracted ${t.length} script embedded codes from script tags`),t}function ge(e,t){let n=null;for(let r of e.mappings)if(r.sourceOffsets[0]+r.lengths[0]===t){n=r;break}if(!n)return null;let r=n.generatedLengths[0],i=n.generatedOffsets[0]+r;e.code=e.code.substring(0,i)+`.`+e.code.substring(i);let a={sourceOffsets:[t],generatedOffsets:[i],lengths:[1],generatedLengths:[1],data:{...n.data}},o=e.mappings.indexOf(n);e.mappings.splice(o+1,0,a);for(let r of e.mappings)r!==n&&r!==a&&r.generatedOffsets[0]>=i&&(r.generatedOffsets[0]+=1),r!==n&&r!==a&&r.sourceOffsets[0]>=t&&(r.sourceOffsets[0]+=1);return i}const _e=new Map,Z=new Map;function ve(e){return typeof e==`string`?e:e.fsPath.replace(/\\/g,`/`)}function Q(e,t=u.default.existsSync){let n=e,r=[];for(;n;){if(Z.has(n)){let e=Z.get(n)??null;for(let t of r)Z.set(t,e);return e}r.push(n);let e=d.default.join(n,`package.json`);if(t(e))try{let t=JSON.parse(u.default.readFileSync(e,`utf8`)),n=new Set([...Object.keys(t.dependencies??{}),...Object.keys(t.devDependencies??{}),...Object.keys(t.peerDependencies??{}),...Object.keys(t.optionalDependencies??{})]),i={name:typeof t.name==`string`?t.name:null,dependencies:n};for(let e of r)Z.set(e,i);return i}catch{for(let e of r)Z.set(e,null);return null}let i=d.default.dirname(n);if(i===n)break;n=i}for(let e of r)Z.set(e,null);return null}function $(e,t,n){if(!e)return!1;if(e.name===t||n.includes(e.name??``)||e.dependencies.has(t))return!0;for(let t of n)if(e.dependencies.has(t))return!0;return!1}function ye(e,t){let n=Se(e,t);if(n)return be(ce(n))}function be(e){return typeof e?.compile_to_volar_mappings!=`function`&&typeof e?.compileToVolarMappings==`function`?{...e,compile_to_volar_mappings:e.compileToVolarMappings}:e}function xe(e,t=u.default.existsSync,n=_e){let r=e.split(`/`),i=d.default.extname(e);for(let e=r.length-2;e>=0;e--){let a=r.slice(0,e+1).join(`/`),o=a+`\0`+i;if(!n.has(o)){let e=[];for(let[n,r,o,s,c=ue]of K)if(o.includes(i))for(let i of c){let o=[a,...r,...i].join(`/`);if(t(o)){e.push([n,o,s]);break}}let r=null;if(e.length>0){let n=Q(a,t);r=e.find(([e,,t])=>$(n,e,t))?.[1]??e[0][1],V(`Found tsrx compiler at:`,r,`for extension:`,i)}n.set(o,r)}let s=n.get(o);if(s)return s}}function Se(e,t){let n=d.default.extname(e),r=oe(e,t);if(r!==void 0)return r??void 0;let i=Q(d.default.dirname(e)),a=xe(e);if(a)return a;let o=`No supported tsrx compiler found in workspace for ${e}.`,s=le;for(;s;){let e=[];for(let[t,r,i,a,o=ue]of K){if(!i.includes(n))continue;let c=d.default.join(s,...r);for(let n of o){let r=d.default.join(c,...n);if(u.default.existsSync(r)){e.push([t,r,a]);break}}}if(e.length>0){let t=e.find(([e,,t])=>$(i,e,t))?.[1]??e[0][1];return H(`${o} Using packaged version at ${t}`),t}let t=d.default.dirname(s);if(t===s)break;s=t}}Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return c}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return pe}});
11
+ //# sourceMappingURL=language-CofXAudP.js.map
@@ -0,0 +1,52 @@
1
+ diff --git a/lib/parse/index.js b/lib/parse/index.js
2
+ index 053f059..ec14409 100644
3
+ --- a/lib/parse/index.js
4
+ +++ b/lib/parse/index.js
5
+ @@ -390,6 +390,39 @@ module.exports = function(css, options){
6
+ }
7
+
8
+
9
+ + /**
10
+ + * Parse layer — block form `@layer name { rules }` (anonymous when the name
11
+ + * is empty) and statement form `@layer a, b;` (declares order only).
12
+ + */
13
+ +
14
+ + function atlayer() {
15
+ + var pos = position();
16
+ + var m = match(/^@layer\s*([^{;]*)/);
17
+ +
18
+ + if (!m) return;
19
+ +
20
+ + var name = trim(m[1]);
21
+ +
22
+ + if (match(/^;/)) {
23
+ + return pos({
24
+ + type: 'layer',
25
+ + layer: name
26
+ + });
27
+ + }
28
+ +
29
+ + if (!open()) return error("@layer missing '{'");
30
+ +
31
+ + var style = comments().concat(rules());
32
+ +
33
+ + if (!close()) return error("@layer missing '}'");
34
+ +
35
+ + return pos({
36
+ + type: 'layer',
37
+ + layer: name,
38
+ + rules: style
39
+ + });
40
+ + }
41
+ +
42
+ /**
43
+ * Parse custom-media.
44
+ */
45
+ @@ -533,6 +566,7 @@ module.exports = function(css, options){
46
+
47
+ return atkeyframes()
48
+ || atmedia()
49
+ + || atlayer()
50
+ || atcustommedia()
51
+ || atsupports()
52
+ || atimport()