@navita/adapter 0.0.0-main-20230917201540

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,5 @@
1
+
2
+ > @navita/adapter@0.0.0-main-20230917201540 build /home/runner/work/navita/navita/packages/adapter
3
+ > build
4
+
5
+ Building @navita/adapter.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @navita/adapter
2
+
3
+ ## 0.0.0-main-20230917201540
4
+
5
+ ### Patch Changes
6
+
7
+ - d2af2ad: Initial public release
package/dist/index.cjs ADDED
@@ -0,0 +1,38 @@
1
+ 'use strict';
2
+
3
+ let adapter = undefined;
4
+ function getAdapter() {
5
+ if (!adapter) {
6
+ throw new Error('Could not find an adapter. Please ensure you have added a bundler integration:\n' + 'https://navita.style/#bundler-integration');
7
+ }
8
+ return adapter;
9
+ }
10
+ const setAdapter = (newAdapter)=>{
11
+ adapter = newAdapter;
12
+ };
13
+ function generateIdentifier(value) {
14
+ return getAdapter().generateIdentifier(value);
15
+ }
16
+ function addCss(css) {
17
+ return getAdapter().addCss(css);
18
+ }
19
+ function addStaticCss(selector, css) {
20
+ return getAdapter().addStaticCss(selector, css);
21
+ }
22
+ function addKeyframe(keyframe) {
23
+ return getAdapter().addKeyframe(keyframe);
24
+ }
25
+ function addFontFace(fontFace) {
26
+ return getAdapter().addFontFace(fontFace);
27
+ }
28
+ function collectResult(input) {
29
+ return getAdapter().collectResult?.(input);
30
+ }
31
+
32
+ exports.addCss = addCss;
33
+ exports.addFontFace = addFontFace;
34
+ exports.addKeyframe = addKeyframe;
35
+ exports.addStaticCss = addStaticCss;
36
+ exports.collectResult = collectResult;
37
+ exports.generateIdentifier = generateIdentifier;
38
+ exports.setAdapter = setAdapter;
@@ -0,0 +1,26 @@
1
+ import { StyleRule, GlobalStyleRule, CSSKeyframes, FontFaceRule } from '@navita/types';
2
+
3
+ type Adapter = {
4
+ generateIdentifier: typeof generateIdentifier;
5
+ addCss: typeof addCss;
6
+ addStaticCss: typeof addStaticCss;
7
+ addKeyframe: typeof addKeyframe;
8
+ addFontFace: typeof addFontFace;
9
+ collectResult?: typeof collectResult;
10
+ };
11
+ declare const setAdapter: (newAdapter: Adapter) => void;
12
+ declare function generateIdentifier(value: unknown): string;
13
+ declare function addCss(css: StyleRule): string;
14
+ declare function addStaticCss(selector: string, css: GlobalStyleRule): void;
15
+ declare function addKeyframe(keyframe: CSSKeyframes): string;
16
+ declare function addFontFace(fontFace: FontFaceRule | FontFaceRule[]): string;
17
+ declare function collectResult<T>(input: {
18
+ filePath: string;
19
+ index: number;
20
+ result: () => T;
21
+ identifier?: string;
22
+ line: number;
23
+ column: number;
24
+ }): T;
25
+
26
+ export { Adapter, addCss, addFontFace, addKeyframe, addStaticCss, collectResult, generateIdentifier, setAdapter };
@@ -0,0 +1,10 @@
1
+ {
2
+ "name": "@navita/adapter",
3
+ "version": "0.0.0-main-20230917201540",
4
+ "exports": {
5
+ ".": {
6
+ "types": "./index.d.ts",
7
+ "default": "./index.cjs"
8
+ }
9
+ }
10
+ }
package/package.json ADDED
@@ -0,0 +1,18 @@
1
+ {
2
+ "name": "@navita/adapter",
3
+ "version": "0.0.0-main-20230917201540",
4
+ "exports": {
5
+ ".": {
6
+ "types": "./src/index.ts",
7
+ "default": "./dist/index.cjs"
8
+ }
9
+ },
10
+ "devDependencies": {
11
+ "@navita/types": "0.0.0-main-20230917201540"
12
+ },
13
+ "scripts": {
14
+ "build": "build",
15
+ "dev": "build --dev",
16
+ "test": "jest"
17
+ }
18
+ }
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ import type { CSSKeyframes, GlobalStyleRule, StyleRule, FontFaceRule } from "@navita/types";
2
+
3
+ export type Adapter = {
4
+ generateIdentifier: typeof generateIdentifier,
5
+ addCss: typeof addCss,
6
+ addStaticCss: typeof addStaticCss,
7
+ addKeyframe: typeof addKeyframe,
8
+ addFontFace: typeof addFontFace,
9
+ collectResult?: typeof collectResult;
10
+ };
11
+
12
+ let adapter: Adapter | undefined = undefined;
13
+
14
+ function getAdapter() {
15
+ if (!adapter) {
16
+ throw new Error(
17
+ 'Could not find an adapter. Please ensure you have added a bundler integration:\n' +
18
+ 'https://navita.style/#bundler-integration',
19
+ );
20
+ }
21
+
22
+ return adapter;
23
+ }
24
+
25
+ export const setAdapter = (newAdapter: Adapter) => {
26
+ adapter = newAdapter;
27
+ }
28
+
29
+ export function generateIdentifier(value: unknown): string {
30
+ return getAdapter().generateIdentifier(value) as string;
31
+ }
32
+
33
+ export function addCss(css: StyleRule): string {
34
+ return getAdapter().addCss(css);
35
+ }
36
+
37
+ export function addStaticCss(selector: string, css: GlobalStyleRule): void {
38
+ return getAdapter().addStaticCss(selector, css);
39
+ }
40
+
41
+ export function addKeyframe(keyframe: CSSKeyframes): string {
42
+ return getAdapter().addKeyframe(keyframe) as string;
43
+ }
44
+
45
+ export function addFontFace(fontFace: FontFaceRule | FontFaceRule[]): string {
46
+ return getAdapter().addFontFace(fontFace) as string;
47
+ }
48
+
49
+ export function collectResult<T>(input: {
50
+ filePath: string,
51
+ index: number,
52
+ result: () => T,
53
+ identifier?: string,
54
+ line: number,
55
+ column: number,
56
+ }): T {
57
+ return getAdapter().collectResult?.(input) as T;
58
+ }
@@ -0,0 +1,57 @@
1
+ import type { Adapter } from "../../src";
2
+ import {
3
+ collectResult,
4
+ generateIdentifier,
5
+ setAdapter,
6
+ addCss,
7
+ addFontFace,
8
+ addKeyframe,
9
+ addStaticCss
10
+ } from "../../src";
11
+
12
+ describe('adapter', () => {
13
+ it('should throw error without adapter', () => {
14
+ expect(() => generateIdentifier('something')).toThrowError();
15
+ expect(() => addCss({})).toThrowError();
16
+ // noinspection JSVoidFunctionReturnValueUsed
17
+ expect(() => addStaticCss('selector', {})).toThrowError();
18
+ expect(() => addKeyframe({})).toThrowError();
19
+ expect(() => addFontFace({
20
+ src: '',
21
+ })).toThrowError();
22
+ expect(() => collectResult({
23
+ index: 0,
24
+ column: 0,
25
+ line: 0,
26
+ filePath: "",
27
+ result: () => undefined
28
+ })).toThrowError();
29
+ });
30
+
31
+ it('should set adapter', () => {
32
+ setAdapter({
33
+ generateIdentifier: () => 'something',
34
+ addCss: () => 'something',
35
+ addStaticCss: () => 'something',
36
+ addKeyframe: () => 'something',
37
+ addFontFace: () => 'something',
38
+ collectResult: () => 'something',
39
+ } as unknown as Adapter);
40
+
41
+ expect(generateIdentifier('anything')).toBe('something');
42
+ expect(addCss({})).toBe('something');
43
+ // noinspection JSVoidFunctionReturnValueUsed
44
+ expect(addStaticCss('selector', {})).toBe('something');
45
+ expect(addKeyframe({})).toBe('something');
46
+ expect(addFontFace({
47
+ src: '',
48
+ })).toBe('something');
49
+ expect(collectResult({
50
+ index: 0,
51
+ column: 0,
52
+ line: 0,
53
+ filePath: "",
54
+ result: () => undefined,
55
+ })).toBe('something');
56
+ });
57
+ });