@ressjs/assets 0.6.0-experimental.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/catalog.d.ts +16 -0
- package/dist/catalog.js +57 -0
- package/dist/client/entry.d.mts +3 -0
- package/dist/client/entry.mjs +2 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +6 -0
- package/dist/components.d.ts +33 -0
- package/dist/components.js +25 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +13 -0
- package/dist/page-assets.d.ts +4 -0
- package/dist/page-assets.js +11 -0
- package/dist/resolve.d.ts +4 -0
- package/dist/resolve.js +18 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.js +2 -0
- package/package.json +42 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type PlatformRegistry } from '@ressjs/platform';
|
|
2
|
+
import type { AssetVariant } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Formatos de estilos soportados, en orden de precedencia.
|
|
5
|
+
*
|
|
6
|
+
* Es una capacidad cerrada del pipeline, no una política configurable del
|
|
7
|
+
* proyecto. Agregar un formato implica implementarlo y probarlo en Ress.
|
|
8
|
+
*/
|
|
9
|
+
export declare const SUPPORTED_STYLE_EXTENSIONS: readonly ["css", "scss", "sass", "less", "styl"];
|
|
10
|
+
/**
|
|
11
|
+
* Descubre las variantes de una hoja sin conocer nada del router.
|
|
12
|
+
*
|
|
13
|
+
* Si existen dos formatos para el mismo sufijo, gana el primero de esta lista
|
|
14
|
+
* (CSS antes que SCSS). Así el resultado no depende del orden del filesystem.
|
|
15
|
+
*/
|
|
16
|
+
export declare function discoverStyleVariants(base: string, registry?: PlatformRegistry): Promise<AssetVariant[]>;
|
package/dist/catalog.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.SUPPORTED_STYLE_EXTENSIONS = void 0;
|
|
7
|
+
exports.discoverStyleVariants = discoverStyleVariants;
|
|
8
|
+
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
9
|
+
const platform_1 = require("@ressjs/platform");
|
|
10
|
+
/**
|
|
11
|
+
* Formatos de estilos soportados, en orden de precedencia.
|
|
12
|
+
*
|
|
13
|
+
* Es una capacidad cerrada del pipeline, no una política configurable del
|
|
14
|
+
* proyecto. Agregar un formato implica implementarlo y probarlo en Ress.
|
|
15
|
+
*/
|
|
16
|
+
exports.SUPPORTED_STYLE_EXTENSIONS = Object.freeze(['css', 'scss', 'sass', 'less', 'styl']);
|
|
17
|
+
/**
|
|
18
|
+
* Descubre las variantes de una hoja sin conocer nada del router.
|
|
19
|
+
*
|
|
20
|
+
* Si existen dos formatos para el mismo sufijo, gana el primero de esta lista
|
|
21
|
+
* (CSS antes que SCSS). Así el resultado no depende del orden del filesystem.
|
|
22
|
+
*/
|
|
23
|
+
async function discoverStyleVariants(base, registry = platform_1.defaultPlatformRegistry) {
|
|
24
|
+
const files = await (0, fast_glob_1.default)(exports.SUPPORTED_STYLE_EXTENSIONS.flatMap((ext) => [`${base}.${ext}`, `${base}.*.${ext}`]), { absolute: false });
|
|
25
|
+
const priority = new Map(exports.SUPPORTED_STYLE_EXTENSIONS.map((ext, index) => [ext, index]));
|
|
26
|
+
const ordered = files.sort((a, b) => {
|
|
27
|
+
const extA = extensionOf(a);
|
|
28
|
+
const extB = extensionOf(b);
|
|
29
|
+
return (priority.get(extA) ?? Number.MAX_SAFE_INTEGER) - (priority.get(extB) ?? Number.MAX_SAFE_INTEGER) || a.localeCompare(b);
|
|
30
|
+
});
|
|
31
|
+
const variants = new Map();
|
|
32
|
+
for (const file of ordered) {
|
|
33
|
+
const suffix = variantSuffixOf(file, base);
|
|
34
|
+
if (variants.has(suffix))
|
|
35
|
+
continue;
|
|
36
|
+
variants.set(suffix, {
|
|
37
|
+
suffix,
|
|
38
|
+
tags: (0, platform_1.parseVariantSuffix)(suffix, registry, file),
|
|
39
|
+
// El catálogo es portable y apto para diagnóstico: conserva la ruta
|
|
40
|
+
// relativa al proyecto. El consumidor que necesite una ruta absoluta
|
|
41
|
+
// (por ejemplo Vite al generar un import virtual) la resuelve en su
|
|
42
|
+
// propio límite.
|
|
43
|
+
sourceFile: file.replace(/\\/g, '/'),
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
if (!variants.has(''))
|
|
47
|
+
variants.set('', { suffix: '', tags: [] });
|
|
48
|
+
return [...variants.values()].sort((a, b) => a.suffix.localeCompare(b.suffix));
|
|
49
|
+
}
|
|
50
|
+
function extensionOf(file) {
|
|
51
|
+
return file.slice(file.lastIndexOf('.') + 1);
|
|
52
|
+
}
|
|
53
|
+
function variantSuffixOf(file, base) {
|
|
54
|
+
const rest = file.slice(base.length);
|
|
55
|
+
const withoutExt = rest.replace(/\.[^.]+$/, '');
|
|
56
|
+
return withoutExt.replace(/^\./, '');
|
|
57
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Style = exports.Script = void 0;
|
|
4
|
+
var components_1 = require("../components");
|
|
5
|
+
Object.defineProperty(exports, "Script", { enumerable: true, get: function () { return components_1.Script; } });
|
|
6
|
+
Object.defineProperty(exports, "Style", { enumerable: true, get: function () { return components_1.Style; } });
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
export interface StyleProps {
|
|
3
|
+
children?: ReactNode;
|
|
4
|
+
media?: string;
|
|
5
|
+
nonce?: string;
|
|
6
|
+
title?: string;
|
|
7
|
+
id?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function Style({ children, media, nonce, title, id }: StyleProps): import("react").DetailedReactHTMLElement<{
|
|
10
|
+
'data-ress-style': string;
|
|
11
|
+
id?: string | undefined;
|
|
12
|
+
title?: string | undefined;
|
|
13
|
+
nonce?: string | undefined;
|
|
14
|
+
media?: string | undefined;
|
|
15
|
+
}, HTMLElement>;
|
|
16
|
+
export interface ScriptProps {
|
|
17
|
+
children?: ReactNode;
|
|
18
|
+
src?: string;
|
|
19
|
+
type?: string;
|
|
20
|
+
nonce?: string;
|
|
21
|
+
id?: string;
|
|
22
|
+
async?: boolean;
|
|
23
|
+
defer?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export declare function Script({ children, src, type, nonce, id, async, defer }: ScriptProps): import("react").DetailedReactHTMLElement<{
|
|
26
|
+
'data-ress-script': string;
|
|
27
|
+
defer?: boolean | undefined;
|
|
28
|
+
async?: boolean | undefined;
|
|
29
|
+
id?: string | undefined;
|
|
30
|
+
nonce?: string | undefined;
|
|
31
|
+
type?: string | undefined;
|
|
32
|
+
src?: string | undefined;
|
|
33
|
+
}, HTMLElement>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Style = Style;
|
|
4
|
+
exports.Script = Script;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
function Style({ children, media, nonce, title, id }) {
|
|
7
|
+
return (0, react_1.createElement)('style', {
|
|
8
|
+
...(media ? { media } : {}),
|
|
9
|
+
...(nonce ? { nonce } : {}),
|
|
10
|
+
...(title ? { title } : {}),
|
|
11
|
+
...(id ? { id } : {}),
|
|
12
|
+
'data-ress-style': 'inline',
|
|
13
|
+
}, children);
|
|
14
|
+
}
|
|
15
|
+
function Script({ children, src, type, nonce, id, async, defer }) {
|
|
16
|
+
return (0, react_1.createElement)('script', {
|
|
17
|
+
...(src ? { src } : {}),
|
|
18
|
+
...(type ? { type } : {}),
|
|
19
|
+
...(nonce ? { nonce } : {}),
|
|
20
|
+
...(id ? { id } : {}),
|
|
21
|
+
...(async ? { async: true } : {}),
|
|
22
|
+
...(defer ? { defer: true } : {}),
|
|
23
|
+
'data-ress-script': children != null ? 'inline' : 'external',
|
|
24
|
+
}, children);
|
|
25
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { SUPPORTED_STYLE_EXTENSIONS, discoverStyleVariants } from './catalog';
|
|
2
|
+
export { resolveAssetVariant } from './resolve';
|
|
3
|
+
export { resolvePageAssets } from './page-assets';
|
|
4
|
+
export { Script, Style } from './components';
|
|
5
|
+
export type { AssetCatalog, AssetDefinition, AssetEntry, AssetIndex, AssetResolverOptions, AssetVariant, ResolvedAssetLinks } from './types';
|
|
6
|
+
export type { ScriptProps, StyleProps } from './components';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Style = exports.Script = exports.resolvePageAssets = exports.resolveAssetVariant = exports.discoverStyleVariants = exports.SUPPORTED_STYLE_EXTENSIONS = void 0;
|
|
4
|
+
var catalog_1 = require("./catalog");
|
|
5
|
+
Object.defineProperty(exports, "SUPPORTED_STYLE_EXTENSIONS", { enumerable: true, get: function () { return catalog_1.SUPPORTED_STYLE_EXTENSIONS; } });
|
|
6
|
+
Object.defineProperty(exports, "discoverStyleVariants", { enumerable: true, get: function () { return catalog_1.discoverStyleVariants; } });
|
|
7
|
+
var resolve_1 = require("./resolve");
|
|
8
|
+
Object.defineProperty(exports, "resolveAssetVariant", { enumerable: true, get: function () { return resolve_1.resolveAssetVariant; } });
|
|
9
|
+
var page_assets_1 = require("./page-assets");
|
|
10
|
+
Object.defineProperty(exports, "resolvePageAssets", { enumerable: true, get: function () { return page_assets_1.resolvePageAssets; } });
|
|
11
|
+
var components_1 = require("./components");
|
|
12
|
+
Object.defineProperty(exports, "Script", { enumerable: true, get: function () { return components_1.Script; } });
|
|
13
|
+
Object.defineProperty(exports, "Style", { enumerable: true, get: function () { return components_1.Style; } });
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type PlatformInfo, type PlatformRegistry } from '@ressjs/platform';
|
|
2
|
+
import type { AssetCatalog, AssetIndex, ResolvedAssetLinks } from './types';
|
|
3
|
+
/** Resolves already-built links for one page and platform without filesystem access. */
|
|
4
|
+
export declare function resolvePageAssets(pageId: string, platform: PlatformInfo | undefined, catalog: AssetCatalog, assets: AssetIndex, registry?: PlatformRegistry): ResolvedAssetLinks;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolvePageAssets = resolvePageAssets;
|
|
4
|
+
const platform_1 = require("@ressjs/platform");
|
|
5
|
+
const resolve_1 = require("./resolve");
|
|
6
|
+
/** Resolves already-built links for one page and platform without filesystem access. */
|
|
7
|
+
function resolvePageAssets(pageId, platform = platform_1.DEFAULT_PLATFORM, catalog, assets, registry = platform_1.defaultPlatformRegistry) {
|
|
8
|
+
const variants = catalog.variantsByPage.get(pageId) ?? [];
|
|
9
|
+
const chosen = variants.length ? (0, resolve_1.resolveAssetVariant)(platform, variants, registry) : undefined;
|
|
10
|
+
return (chosen && assets.find(pageId, chosen.suffix)) ?? assets.find(pageId, '') ?? { js: '', css: [] };
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { PlatformInfo, PlatformRegistry } from '@ressjs/platform';
|
|
2
|
+
import type { AssetVariant } from './types';
|
|
3
|
+
/** Selecciona la variante más específica para una plataforma. */
|
|
4
|
+
export declare function resolveAssetVariant(platform: PlatformInfo, available: AssetVariant[], registry: PlatformRegistry): AssetVariant;
|
package/dist/resolve.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.resolveAssetVariant = resolveAssetVariant;
|
|
4
|
+
/** Selecciona la variante más específica para una plataforma. */
|
|
5
|
+
function resolveAssetVariant(platform, available, registry) {
|
|
6
|
+
const base = available.find((variant) => variant.suffix === '');
|
|
7
|
+
const applicable = available.filter((variant) => variant.tags.every((tag) => registry.matches(tag, platform)));
|
|
8
|
+
if (!applicable.length) {
|
|
9
|
+
if (!base)
|
|
10
|
+
throw new Error('[ress] No hay una variante base para este asset.');
|
|
11
|
+
return base;
|
|
12
|
+
}
|
|
13
|
+
return applicable.reduce((best, candidate) => {
|
|
14
|
+
if (candidate.tags.length !== best.tags.length)
|
|
15
|
+
return candidate.tags.length > best.tags.length ? candidate : best;
|
|
16
|
+
return candidate.suffix.localeCompare(best.suffix) < 0 ? candidate : best;
|
|
17
|
+
});
|
|
18
|
+
}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { PlatformRegistry, VariantTag } from '@ressjs/platform';
|
|
2
|
+
export interface AssetVariant {
|
|
3
|
+
suffix: string;
|
|
4
|
+
tags: VariantTag[];
|
|
5
|
+
sourceFile?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface AssetEntry {
|
|
8
|
+
name: string;
|
|
9
|
+
sourceFile: string;
|
|
10
|
+
variants: AssetVariant[];
|
|
11
|
+
}
|
|
12
|
+
export interface AssetDefinition {
|
|
13
|
+
entries?: Record<string, string>;
|
|
14
|
+
}
|
|
15
|
+
export interface AssetResolverOptions {
|
|
16
|
+
registry: PlatformRegistry;
|
|
17
|
+
}
|
|
18
|
+
export interface ResolvedAssetLinks {
|
|
19
|
+
js: string;
|
|
20
|
+
css: string[];
|
|
21
|
+
}
|
|
22
|
+
/** Minimal shape consumed by the request resolver; the router owns its catalog details. */
|
|
23
|
+
export interface AssetCatalog {
|
|
24
|
+
variantsByPage: Map<string, AssetVariant[]>;
|
|
25
|
+
}
|
|
26
|
+
export interface AssetIndex {
|
|
27
|
+
find(pageId: string, variantSuffix: string): ResolvedAssetLinks | undefined;
|
|
28
|
+
}
|
package/dist/types.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ressjs/assets",
|
|
3
|
+
"version": "0.6.0-experimental.0",
|
|
4
|
+
"description": "Assets de ress.js: variantes de plataforma, Style y Script",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"require": "./dist/index.js",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./client": {
|
|
14
|
+
"types": "./dist/client/entry.d.mts",
|
|
15
|
+
"require": "./dist/client/index.js",
|
|
16
|
+
"import": "./dist/client/entry.mjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsc",
|
|
24
|
+
"dev": "tsc --watch",
|
|
25
|
+
"clean": "rm -rf dist",
|
|
26
|
+
"test": "vitest run",
|
|
27
|
+
"prepublishOnly": "npm run build"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {
|
|
33
|
+
"@ressjs/platform": "0.6.0-experimental.0",
|
|
34
|
+
"fast-glob": "^3.3.3"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"react": "^19.0.0"
|
|
38
|
+
},
|
|
39
|
+
"engines": {
|
|
40
|
+
"node": ">=20.19.0"
|
|
41
|
+
}
|
|
42
|
+
}
|