@newtonedev/configurator 0.1.4 → 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.js CHANGED
@@ -2,6 +2,7 @@ import React, { useReducer, useMemo, useCallback, useRef, useState, useEffect }
2
2
  import { StyleSheet, View, Pressable, Text } from 'react-native';
3
3
  import { computeTokens, useTokens, useNewtoneTheme, Toggle, Card, Slider, Select, HueSlider, NewtoneProvider, ColorScaleSlider, TextInput, Button } from '@newtonedev/components';
4
4
  import { srgbToOklch, generatePreview, getColor, getColorByContrast, lightnessToNormalizedValue, getWcagContrastRatio, hexToSrgb, findMaxChromaInGamut, srgbToHex } from 'newtone';
5
+ import { applyTypeScaleOffset, DEFAULT_ROLE_SCALES, ROLE_DEFAULT_WEIGHTS, DEFAULT_LINE_HEIGHTS, DEFAULT_FONT_SIZES, computeBreakpointRoleScales, migrateToFontSlot, DEFAULT_FONT_SLOTS } from '@newtonedev/fonts';
5
6
 
6
7
  // src/Configurator.tsx
7
8
 
@@ -80,23 +81,39 @@ var DEFAULT_CONFIGURATOR_STATE = {
80
81
  },
81
82
  typography: {
82
83
  fonts: {
83
- mono: {
84
- type: "system",
85
- family: "ui-monospace",
86
- fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
84
+ main: {
85
+ config: {
86
+ type: "system",
87
+ family: "system-ui",
88
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
89
+ },
90
+ weights: { regular: 400, medium: 500, bold: 700 }
87
91
  },
88
92
  display: {
89
- type: "system",
90
- family: "system-ui",
91
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
93
+ config: {
94
+ type: "system",
95
+ family: "system-ui",
96
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
97
+ },
98
+ weights: { regular: 400, medium: 500, bold: 700 }
99
+ },
100
+ mono: {
101
+ config: {
102
+ type: "system",
103
+ family: "ui-monospace",
104
+ fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
105
+ },
106
+ weights: { regular: 400, medium: 500, bold: 700 }
92
107
  },
93
- default: {
94
- type: "system",
95
- family: "system-ui",
96
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
108
+ currency: {
109
+ config: {
110
+ type: "system",
111
+ family: "system-ui",
112
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
113
+ },
114
+ weights: { regular: 400, medium: 500, bold: 700 }
97
115
  }
98
- },
99
- scale: { baseSize: 16, ratio: 1.25 }
116
+ }
100
117
  },
101
118
  icons: {
102
119
  variant: "rounded",
@@ -284,71 +301,40 @@ function configuratorReducer(state, action) {
284
301
  }
285
302
  };
286
303
  // Typography actions
287
- case "SET_TYPOGRAPHY_BASE_SIZE": {
288
- const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
289
- return {
290
- ...state,
291
- typography: {
292
- fonts: state.typography?.fonts ?? defaultTypography.fonts,
293
- scale: {
294
- baseSize: clamp(action.baseSize, 12, 24),
295
- ratio: state.typography?.scale.ratio ?? defaultTypography.scale.ratio
296
- }
297
- }
298
- };
299
- }
300
- case "SET_TYPOGRAPHY_RATIO": {
301
- const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
302
- return {
303
- ...state,
304
- typography: {
305
- fonts: state.typography?.fonts ?? defaultTypography.fonts,
306
- scale: {
307
- baseSize: state.typography?.scale.baseSize ?? defaultTypography.scale.baseSize,
308
- ratio: clamp(action.ratio, 1.1, 1.5)
309
- }
310
- }
311
- };
312
- }
313
- case "SET_FONT_MONO": {
304
+ case "SET_FONT": {
314
305
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
306
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
315
307
  return {
316
308
  ...state,
317
309
  typography: {
318
- fonts: {
319
- mono: action.font,
320
- display: state.typography?.fonts.display ?? defaultTypography.fonts.display,
321
- default: state.typography?.fonts.default ?? defaultTypography.fonts.default
322
- },
323
- scale: state.typography?.scale ?? defaultTypography.scale
310
+ fonts: { ...currentFonts, [action.scope]: action.font }
324
311
  }
325
312
  };
326
313
  }
327
- case "SET_FONT_DISPLAY": {
314
+ case "SET_TYPE_SCALE_OFFSET": {
328
315
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
316
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
329
317
  return {
330
318
  ...state,
331
319
  typography: {
332
- fonts: {
333
- mono: state.typography?.fonts.mono ?? defaultTypography.fonts.mono,
334
- display: action.font,
335
- default: state.typography?.fonts.default ?? defaultTypography.fonts.default
336
- },
337
- scale: state.typography?.scale ?? defaultTypography.scale
320
+ ...state.typography,
321
+ fonts: currentFonts,
322
+ typeScaleOffset: clamp(action.offset, 0, 1)
338
323
  }
339
324
  };
340
325
  }
341
- case "SET_FONT_DEFAULT": {
326
+ case "SET_ROLE_WEIGHT": {
342
327
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
328
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
343
329
  return {
344
330
  ...state,
345
331
  typography: {
346
- fonts: {
347
- mono: state.typography?.fonts.mono ?? defaultTypography.fonts.mono,
348
- display: state.typography?.fonts.display ?? defaultTypography.fonts.display,
349
- default: action.font
350
- },
351
- scale: state.typography?.scale ?? defaultTypography.scale
332
+ ...state.typography,
333
+ fonts: currentFonts,
334
+ roleWeights: {
335
+ ...state.typography?.roleWeights,
336
+ [action.role]: clamp(action.weight, 100, 900)
337
+ }
352
338
  }
353
339
  };
354
340
  }
@@ -449,34 +435,6 @@ var SPACING_PRESET_TO_BASE = {
449
435
  function roundnessToMultiplier(intensity) {
450
436
  return intensity * 2;
451
437
  }
452
- function computeTypographyScale(baseSize, ratio) {
453
- return {
454
- xs: Math.round(baseSize / ratio ** 2),
455
- sm: Math.round(baseSize / ratio),
456
- base: baseSize,
457
- md: Math.round(baseSize * ratio),
458
- lg: Math.round(baseSize * ratio ** 2),
459
- xl: Math.round(baseSize * ratio ** 3),
460
- xxl: Math.round(baseSize * ratio ** 4)
461
- };
462
- }
463
- var DEFAULT_FONTS = {
464
- mono: {
465
- type: "system",
466
- family: "ui-monospace",
467
- fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
468
- },
469
- display: {
470
- type: "system",
471
- family: "system-ui",
472
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
473
- },
474
- default: {
475
- type: "system",
476
- family: "system-ui",
477
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
478
- }
479
- };
480
438
  var DEFAULT_ICONS = {
481
439
  variant: "rounded",
482
440
  // Material Design 3 aesthetic
@@ -540,15 +498,22 @@ function toThemeConfig(state) {
540
498
  xl: Math.round(12 * radiusMultiplier),
541
499
  pill: 999
542
500
  },
543
- typography: {
544
- fonts: state.typography?.fonts ?? DEFAULT_FONTS,
545
- scale: computeTypographyScale(
546
- state.typography?.scale.baseSize ?? 16,
547
- state.typography?.scale.ratio ?? 1.25
548
- ),
549
- lineHeight: { tight: 1.25, normal: 1.5, relaxed: 1.75 },
550
- fontWeight: { regular: 400, medium: 500, semibold: 600, bold: 700 }
551
- },
501
+ typography: (() => {
502
+ const roles = state.typography?.typeScaleOffset != null ? applyTypeScaleOffset(DEFAULT_ROLE_SCALES, state.typography.typeScaleOffset) : DEFAULT_ROLE_SCALES;
503
+ return {
504
+ fonts: {
505
+ main: migrateToFontSlot(state.typography?.fonts.main ?? state.typography?.fonts?.default, DEFAULT_FONT_SLOTS.main),
506
+ display: migrateToFontSlot(state.typography?.fonts.display, DEFAULT_FONT_SLOTS.display),
507
+ mono: migrateToFontSlot(state.typography?.fonts.mono, DEFAULT_FONT_SLOTS.mono),
508
+ currency: migrateToFontSlot(state.typography?.fonts.currency, DEFAULT_FONT_SLOTS.currency)
509
+ },
510
+ fontSizes: DEFAULT_FONT_SIZES,
511
+ lineHeights: DEFAULT_LINE_HEIGHTS,
512
+ roles,
513
+ breakpointRoles: computeBreakpointRoleScales(roles),
514
+ roleWeights: { ...ROLE_DEFAULT_WEIGHTS, ...state.typography?.roleWeights }
515
+ };
516
+ })(),
552
517
  icons: state.icons ?? DEFAULT_ICONS
553
518
  };
554
519
  }
@@ -1195,8 +1160,6 @@ function DesignPanel({ state, dispatch }) {
1195
1160
  const tokens = useTokens(1);
1196
1161
  const spacingPreset = state.spacing?.preset ?? "md";
1197
1162
  const intensity = state.roundness?.intensity ?? 0.5;
1198
- const baseSize = state.typography?.scale.baseSize ?? 16;
1199
- const ratio = state.typography?.scale.ratio ?? 1.25;
1200
1163
  const variant = state.icons?.variant ?? "rounded";
1201
1164
  const weight = state.icons?.weight ?? 400;
1202
1165
  return /* @__PURE__ */ React.createElement(Card, { elevation: 1, style: styles5.container }, /* @__PURE__ */ React.createElement(Text, { style: [styles5.title, { color: srgbToHex(tokens.textPrimary.srgb) }] }, "Design System"), /* @__PURE__ */ React.createElement(Text, { style: [styles5.subtitle, { color: srgbToHex(tokens.textSecondary.srgb) }] }, "Spacing"), /* @__PURE__ */ React.createElement(
@@ -1223,29 +1186,7 @@ function DesignPanel({ state, dispatch }) {
1223
1186
  label: "Intensity",
1224
1187
  showValue: true
1225
1188
  }
1226
- ), /* @__PURE__ */ React.createElement(Text, { style: [styles5.subtitle, { color: srgbToHex(tokens.textSecondary.srgb) }] }, "Typography"), /* @__PURE__ */ React.createElement(View, { style: styles5.row }, /* @__PURE__ */ React.createElement(View, { style: styles5.flex }, /* @__PURE__ */ React.createElement(
1227
- Slider,
1228
- {
1229
- value: baseSize,
1230
- onValueChange: (v) => dispatch({ type: "SET_TYPOGRAPHY_BASE_SIZE", baseSize: v }),
1231
- min: 12,
1232
- max: 24,
1233
- step: 1,
1234
- label: "Base Size",
1235
- showValue: true
1236
- }
1237
- )), /* @__PURE__ */ React.createElement(View, { style: styles5.flex }, /* @__PURE__ */ React.createElement(
1238
- Slider,
1239
- {
1240
- value: Math.round(ratio * 100),
1241
- onValueChange: (v) => dispatch({ type: "SET_TYPOGRAPHY_RATIO", ratio: v / 100 }),
1242
- min: 110,
1243
- max: 150,
1244
- step: 5,
1245
- label: "Scale Ratio",
1246
- showValue: true
1247
- }
1248
- ))), /* @__PURE__ */ React.createElement(Text, { style: [styles5.subtitle, { color: srgbToHex(tokens.textSecondary.srgb) }] }, "Icons"), /* @__PURE__ */ React.createElement(View, { style: styles5.row }, /* @__PURE__ */ React.createElement(View, { style: styles5.flex }, /* @__PURE__ */ React.createElement(
1189
+ ), /* @__PURE__ */ React.createElement(Text, { style: [styles5.subtitle, { color: srgbToHex(tokens.textSecondary.srgb) }] }, "Icons"), /* @__PURE__ */ React.createElement(View, { style: styles5.row }, /* @__PURE__ */ React.createElement(View, { style: styles5.flex }, /* @__PURE__ */ React.createElement(
1249
1190
  Select,
1250
1191
  {
1251
1192
  options: ICON_VARIANT_OPTIONS,