css-engine-test-pb 0.1.3 → 0.1.5

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.d.ts CHANGED
@@ -6,4 +6,5 @@ export { makeStyles } from './makeStyles';
6
6
  export { makeResetStyles } from './makeResetStyles';
7
7
  export { mergeClasses } from './mergeClasses';
8
8
  export { makeStaticStyles } from './makeStaticStyles';
9
- export type { StyleRule, CSSProperties, GeneratedClasses, StyleSlots } from './types';
9
+ export { makeFontFace } from './makeFontFace';
10
+ export type { StyleRule, CSSProperties, GeneratedClasses, StyleSlots, FontFaceDefinition } from './types';
package/dist/index.js CHANGED
@@ -6,3 +6,4 @@ export { makeStyles } from './makeStyles';
6
6
  export { makeResetStyles } from './makeResetStyles';
7
7
  export { mergeClasses } from './mergeClasses';
8
8
  export { makeStaticStyles } from './makeStaticStyles';
9
+ export { makeFontFace } from './makeFontFace';
@@ -0,0 +1,2 @@
1
+ import type { FontFaceDefinition } from './types';
2
+ export declare function makeFontFace(fonts: FontFaceDefinition | FontFaceDefinition[]): () => void;
@@ -0,0 +1,70 @@
1
+ import { getGlobalEngine } from './engine';
2
+ import { StyleBucket } from './types';
3
+ export function makeFontFace(fonts) {
4
+ const engine = getGlobalEngine();
5
+ const fontsArray = Array.isArray(fonts) ? fonts : [fonts];
6
+ let inserted = false;
7
+ return function useFontFace() {
8
+ if (inserted) {
9
+ return;
10
+ }
11
+ fontsArray.forEach(font => {
12
+ const properties = [];
13
+ // Required properties
14
+ properties.push(`font-family: ${quoteIfNeeded(font.fontFamily)}`);
15
+ properties.push(`src: ${font.src}`);
16
+ // Optional properties
17
+ if (font.fontWeight !== undefined) {
18
+ properties.push(`font-weight: ${font.fontWeight}`);
19
+ }
20
+ if (font.fontStyle !== undefined) {
21
+ properties.push(`font-style: ${font.fontStyle}`);
22
+ }
23
+ if (font.fontDisplay !== undefined) {
24
+ properties.push(`font-display: ${font.fontDisplay}`);
25
+ }
26
+ if (font.unicodeRange !== undefined) {
27
+ properties.push(`unicode-range: ${font.unicodeRange}`);
28
+ }
29
+ if (font.fontStretch !== undefined) {
30
+ properties.push(`font-stretch: ${font.fontStretch}`);
31
+ }
32
+ if (font.fontVariant !== undefined) {
33
+ properties.push(`font-variant: ${font.fontVariant}`);
34
+ }
35
+ if (font.fontFeatureSettings !== undefined) {
36
+ properties.push(`font-feature-settings: ${font.fontFeatureSettings}`);
37
+ }
38
+ if (font.fontVariationSettings !== undefined) {
39
+ properties.push(`font-variation-settings: ${font.fontVariationSettings}`);
40
+ }
41
+ if (font.ascentOverride !== undefined) {
42
+ properties.push(`ascent-override: ${font.ascentOverride}`);
43
+ }
44
+ if (font.descentOverride !== undefined) {
45
+ properties.push(`descent-override: ${font.descentOverride}`);
46
+ }
47
+ if (font.lineGapOverride !== undefined) {
48
+ properties.push(`line-gap-override: ${font.lineGapOverride}`);
49
+ }
50
+ const cssRule = `@font-face { ${properties.join('; ')}; }`;
51
+ engine['insertion'].insertRule(cssRule, StyleBucket.RESET);
52
+ });
53
+ inserted = true;
54
+ };
55
+ }
56
+ function quoteIfNeeded(fontFamily) {
57
+ // If already quoted or is a generic family, return as-is
58
+ if (fontFamily.startsWith('"') || fontFamily.startsWith("'")) {
59
+ return fontFamily;
60
+ }
61
+ const genericFamilies = ['serif', 'sans-serif', 'monospace', 'cursive', 'fantasy', 'system-ui'];
62
+ if (genericFamilies.includes(fontFamily.toLowerCase())) {
63
+ return fontFamily;
64
+ }
65
+ // Quote font family names with spaces or special characters
66
+ if (/[\s\-]/.test(fontFamily)) {
67
+ return `"${fontFamily}"`;
68
+ }
69
+ return fontFamily;
70
+ }
@@ -16,7 +16,14 @@ export function makeStaticStyles(styles) {
16
16
  return `${kebabProp}: ${value};`;
17
17
  })
18
18
  .join(' ');
19
- const cssRule = `${selector} { ${cssProperties} }`;
19
+ let cssRule;
20
+ // Handle @font-face specially - it's an at-rule, not a selector
21
+ if (selector === '@font-face') {
22
+ cssRule = `@font-face { ${cssProperties} }`;
23
+ }
24
+ else {
25
+ cssRule = `${selector} { ${cssProperties} }`;
26
+ }
20
27
  engine['insertion'].insertRule(cssRule, StyleBucket.RESET);
21
28
  });
22
29
  });
@@ -1,2 +1,2 @@
1
1
  import { StyleSlots } from './types';
2
- export declare function makeStyles(slots: StyleSlots): () => import("./types").GeneratedClasses;
2
+ export declare function makeStyles(slots: StyleSlots): () => Record<string, string>;
package/dist/types.d.ts CHANGED
@@ -167,3 +167,18 @@ export type MakeStylesFunction = () => GeneratedClasses;
167
167
  export interface StyleSlots {
168
168
  [slotName: string]: StyleDefinition;
169
169
  }
170
+ export interface FontFaceDefinition {
171
+ fontFamily: string;
172
+ src: string;
173
+ fontWeight?: CSSValue;
174
+ fontStyle?: 'normal' | 'italic' | 'oblique' | string;
175
+ fontDisplay?: 'auto' | 'block' | 'swap' | 'fallback' | 'optional';
176
+ unicodeRange?: string;
177
+ fontStretch?: CSSValue;
178
+ fontVariant?: CSSValue;
179
+ fontFeatureSettings?: string;
180
+ fontVariationSettings?: string;
181
+ ascentOverride?: string;
182
+ descentOverride?: string;
183
+ lineGapOverride?: string;
184
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "css-engine-test-pb",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",