@erudit-js/core 4.2.0-dev.1 → 4.3.0-dev.1

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.
@@ -1,4 +1,41 @@
1
- import gradient from 'gradient-string';
2
1
  import { brandColors, brandLogotype } from './brand.js';
3
- export const brandColorLogotype = gradient(brandColors).multiline(brandLogotype);
4
- export const brandColorTitle = gradient(brandColors)('Erudit');
2
+ function hexToRgb(hex) {
3
+ const n = parseInt(hex.replace('#', ''), 16);
4
+ return [(n >> 16) & 0xff, (n >> 8) & 0xff, n & 0xff];
5
+ }
6
+ function lerp(a, b, t) {
7
+ return Math.round(a + (b - a) * t);
8
+ }
9
+ function colorChar(char, t, rgbColors) {
10
+ const segments = rgbColors.length - 1;
11
+ const scaled = t * segments;
12
+ const seg = Math.min(Math.floor(scaled), segments - 1);
13
+ const localT = scaled - seg;
14
+ const [r1, g1, b1] = rgbColors[seg];
15
+ const [r2, g2, b2] = rgbColors[seg + 1];
16
+ return `\x1b[38;2;${lerp(r1, r2, localT)};${lerp(g1, g2, localT)};${lerp(b1, b2, localT)}m${char}`;
17
+ }
18
+ /** Apply gradient across each line independently (matching gradient-string's .multiline()). */
19
+ function gradientMultiline(text, colors) {
20
+ const rgbColors = colors.map(hexToRgb);
21
+ return text
22
+ .split('\n')
23
+ .map((line) => {
24
+ if (line.length === 0)
25
+ return line;
26
+ return ([...line]
27
+ .map((char, i) => colorChar(char, i / (line.length - 1 || 1), rgbColors))
28
+ .join('') + '\x1b[0m');
29
+ })
30
+ .join('\n');
31
+ }
32
+ /** Apply gradient across all characters in a single string. */
33
+ function gradientText(text, colors) {
34
+ const rgbColors = colors.map(hexToRgb);
35
+ const chars = [...text];
36
+ const total = chars.length - 1 || 1;
37
+ return (chars.map((char, i) => colorChar(char, i / total, rgbColors)).join('') +
38
+ '\x1b[0m');
39
+ }
40
+ export const brandColorLogotype = gradientMultiline(brandLogotype, brandColors);
41
+ export const brandColorTitle = gradientText('Erudit', brandColors);
@@ -1,7 +1,7 @@
1
1
  import type { GlobalContributorTypeguard } from '../contributor.js';
2
2
  export interface ConfigContributionDescribed {
3
3
  contributor: GlobalContributorTypeguard;
4
- description: string;
4
+ description?: string;
5
5
  }
6
6
  export type ConfigContribution = GlobalContributorTypeguard | ConfigContributionDescribed;
7
7
  export type IContributable = {
@@ -0,0 +1,7 @@
1
+ export interface EruditDependency {
2
+ transpile?: boolean;
3
+ optimize?: boolean;
4
+ }
5
+ export type EruditDependencies = {
6
+ [dependencyName: string]: EruditDependency;
7
+ };
@@ -1,4 +1,4 @@
1
- import type { Nuxt } from '@nuxt/schema';
1
+ import type { Nuxt } from 'nuxt/schema';
2
2
  import type { NitroConfig } from 'nitropack';
3
3
  import type { EruditIndexPage } from './indexPage.js';
4
4
  import type { EruditSponsors } from '../sponsor.js';
@@ -8,10 +8,10 @@ import type { EruditDebug } from './debug.js';
8
8
  import type { EruditRepository } from './repository.js';
9
9
  import type { EruditSeo } from './seo.js';
10
10
  import type { EruditLanguage } from './language.js';
11
- import type { EruditElements } from './elements.js';
12
11
  import type { EruditContributors } from '../contributor.js';
13
12
  import type { EruditAsideMajor } from './asideMajor.js';
14
13
  import type { EruditFavicons } from './favicons.js';
14
+ import type { EruditDependencies } from '../dependencies.js';
15
15
  export interface EruditConfig {
16
16
  language?: EruditLanguage;
17
17
  debug?: EruditDebug;
@@ -29,18 +29,28 @@ export interface EruditConfig {
29
29
  sponsors?: EruditSponsors;
30
30
  seo?: EruditSeo;
31
31
  repository?: EruditRepository;
32
- elements?: EruditElements;
32
+ elements?: string[];
33
33
  countElements?: (string | string[])[];
34
+ problemChecks?: string[];
35
+ /**
36
+ * Files whose named exports become globally available
37
+ * in all content files (no imports needed).
38
+ *
39
+ * Paths are resolved relative to the project root,
40
+ * just like `elements` and `problemChecks`.
41
+ *
42
+ * @example ['./my-globals']
43
+ */
44
+ autoImports?: string[];
45
+ dependencies?: EruditDependencies;
34
46
  /**
35
47
  * Erudit uses Nuxt under the hood.
36
48
  * Use this to alter Nuxt configuration.
37
49
  */
38
- nuxtAugmentations?: [
39
- ({ nuxt, nitro, projectPath, eruditPath, }: {
40
- nuxt: Nuxt;
41
- nitro: NitroConfig;
42
- projectPath: string;
43
- eruditPath: string;
44
- }) => Promise<void> | void
45
- ];
50
+ nuxtAugmentations?: (({ nuxt, nitro, projectPath, eruditPath, }: {
51
+ nuxt: Nuxt;
52
+ nitro: NitroConfig;
53
+ projectPath: string;
54
+ eruditPath: string;
55
+ }) => Promise<void> | void)[];
46
56
  }
package/dist/mode.d.ts CHANGED
@@ -1 +1,2 @@
1
1
  export type EruditMode = 'dev' | 'write' | 'static';
2
+ export declare function isDevLikeMode(mode: EruditMode): boolean;
package/dist/mode.js CHANGED
@@ -1 +1,3 @@
1
- export {};
1
+ export function isDevLikeMode(mode) {
2
+ return mode === 'dev' || mode === 'write';
3
+ }
@@ -0,0 +1,24 @@
1
+ export type ToProblemCheckDefinition<Name extends string, Data extends any> = {
2
+ name: Name;
3
+ Data: Data;
4
+ };
5
+ export type ProblemCheckDefinition = ToProblemCheckDefinition<string, any>;
6
+ export declare function defineProblemCheck<Name extends string>(name: Name): <Data>() => ToProblemCheckDefinition<Name, Data>;
7
+ export declare const ERUDIT_CHECK_PREFIX = "__ERUDIT_CHECK";
8
+ export type ToProblemCheckObject<Definition extends ProblemCheckDefinition> = {
9
+ [ERUDIT_CHECK_PREFIX]: true;
10
+ name: Definition['name'];
11
+ data: Definition['Data'];
12
+ };
13
+ export type ProblemCheckObject = ToProblemCheckObject<ProblemCheckDefinition>;
14
+ export declare function createProblemCheckObject<Definition extends ProblemCheckDefinition>(definition: Definition, data: Definition['Data']): ToProblemCheckObject<Definition>;
15
+ export declare function isProblemCheckObject(obj: any): obj is ProblemCheckObject;
16
+ export type ToProblemChecker<Definition extends ProblemCheckDefinition> = {
17
+ name: Definition['name'];
18
+ check: (data: Definition['Data'], input: string) => Promise<boolean> | boolean;
19
+ };
20
+ export type ProblemChecker = ToProblemChecker<ProblemCheckDefinition>;
21
+ export type ProblemCheckers = {
22
+ [problemCheckName: string]: ProblemChecker;
23
+ };
24
+ export declare function defineProblemChecker<Definition extends ProblemCheckDefinition>(definition: Definition, handler: ToProblemChecker<Definition>['check']): ToProblemChecker<Definition>;
@@ -0,0 +1,31 @@
1
+ //
2
+ // Problem Check Definition
3
+ //
4
+ export function defineProblemCheck(name) {
5
+ function finalizeProblemCheck() {
6
+ return {
7
+ name,
8
+ };
9
+ }
10
+ return finalizeProblemCheck;
11
+ }
12
+ //
13
+ // Problem Check Object
14
+ //
15
+ export const ERUDIT_CHECK_PREFIX = '__ERUDIT_CHECK';
16
+ export function createProblemCheckObject(definition, data) {
17
+ return {
18
+ [ERUDIT_CHECK_PREFIX]: true,
19
+ name: definition.name,
20
+ data,
21
+ };
22
+ }
23
+ export function isProblemCheckObject(obj) {
24
+ return obj?.[ERUDIT_CHECK_PREFIX] === true;
25
+ }
26
+ export function defineProblemChecker(definition, handler) {
27
+ return {
28
+ name: definition.name,
29
+ check: handler,
30
+ };
31
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@erudit-js/core",
3
- "version": "4.2.0-dev.1",
3
+ "version": "4.3.0-dev.1",
4
4
  "type": "module",
5
5
  "description": "Erudit core essentials",
6
6
  "exports": {
@@ -20,7 +20,6 @@
20
20
  "prepack": "bun run build"
21
21
  },
22
22
  "dependencies": {
23
- "tsprose": "^1.0.0",
24
- "gradient-string": "^3.0.0"
23
+ "tsprose": "^1.0.1"
25
24
  }
26
25
  }
@@ -1 +0,0 @@
1
- export type EruditElements = string[];