@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.
@@ -1 +1 @@
1
- {"version":3,"file":"toThemeConfig.d.ts","sourceRoot":"","sources":["../../src/bridge/toThemeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,UAAU,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAc,MAAM,wBAAwB,CAAC;AAoE7E;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CAqF1E"}
1
+ {"version":3,"file":"toThemeConfig.d.ts","sourceRoot":"","sources":["../../src/bridge/toThemeConfig.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAiB,MAAM,UAAU,CAAC;AACjE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAgCjE;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,iBAAiB,GAAG,kBAAkB,CA8F1E"}
package/dist/index.cjs CHANGED
@@ -4,6 +4,7 @@ var React = require('react');
4
4
  var reactNative = require('react-native');
5
5
  var components = require('@newtonedev/components');
6
6
  var newtone = require('newtone');
7
+ var fonts = require('@newtonedev/fonts');
7
8
 
8
9
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
9
10
 
@@ -86,23 +87,39 @@ var DEFAULT_CONFIGURATOR_STATE = {
86
87
  },
87
88
  typography: {
88
89
  fonts: {
89
- mono: {
90
- type: "system",
91
- family: "ui-monospace",
92
- fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
90
+ main: {
91
+ config: {
92
+ type: "system",
93
+ family: "system-ui",
94
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
95
+ },
96
+ weights: { regular: 400, medium: 500, bold: 700 }
93
97
  },
94
98
  display: {
95
- type: "system",
96
- family: "system-ui",
97
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
99
+ config: {
100
+ type: "system",
101
+ family: "system-ui",
102
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
103
+ },
104
+ weights: { regular: 400, medium: 500, bold: 700 }
105
+ },
106
+ mono: {
107
+ config: {
108
+ type: "system",
109
+ family: "ui-monospace",
110
+ fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
111
+ },
112
+ weights: { regular: 400, medium: 500, bold: 700 }
98
113
  },
99
- default: {
100
- type: "system",
101
- family: "system-ui",
102
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
114
+ currency: {
115
+ config: {
116
+ type: "system",
117
+ family: "system-ui",
118
+ fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
119
+ },
120
+ weights: { regular: 400, medium: 500, bold: 700 }
103
121
  }
104
- },
105
- scale: { baseSize: 16, ratio: 1.25 }
122
+ }
106
123
  },
107
124
  icons: {
108
125
  variant: "rounded",
@@ -290,71 +307,40 @@ function configuratorReducer(state, action) {
290
307
  }
291
308
  };
292
309
  // Typography actions
293
- case "SET_TYPOGRAPHY_BASE_SIZE": {
294
- const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
295
- return {
296
- ...state,
297
- typography: {
298
- fonts: state.typography?.fonts ?? defaultTypography.fonts,
299
- scale: {
300
- baseSize: clamp(action.baseSize, 12, 24),
301
- ratio: state.typography?.scale.ratio ?? defaultTypography.scale.ratio
302
- }
303
- }
304
- };
305
- }
306
- case "SET_TYPOGRAPHY_RATIO": {
307
- const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
308
- return {
309
- ...state,
310
- typography: {
311
- fonts: state.typography?.fonts ?? defaultTypography.fonts,
312
- scale: {
313
- baseSize: state.typography?.scale.baseSize ?? defaultTypography.scale.baseSize,
314
- ratio: clamp(action.ratio, 1.1, 1.5)
315
- }
316
- }
317
- };
318
- }
319
- case "SET_FONT_MONO": {
310
+ case "SET_FONT": {
320
311
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
312
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
321
313
  return {
322
314
  ...state,
323
315
  typography: {
324
- fonts: {
325
- mono: action.font,
326
- display: state.typography?.fonts.display ?? defaultTypography.fonts.display,
327
- default: state.typography?.fonts.default ?? defaultTypography.fonts.default
328
- },
329
- scale: state.typography?.scale ?? defaultTypography.scale
316
+ fonts: { ...currentFonts, [action.scope]: action.font }
330
317
  }
331
318
  };
332
319
  }
333
- case "SET_FONT_DISPLAY": {
320
+ case "SET_TYPE_SCALE_OFFSET": {
334
321
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
322
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
335
323
  return {
336
324
  ...state,
337
325
  typography: {
338
- fonts: {
339
- mono: state.typography?.fonts.mono ?? defaultTypography.fonts.mono,
340
- display: action.font,
341
- default: state.typography?.fonts.default ?? defaultTypography.fonts.default
342
- },
343
- scale: state.typography?.scale ?? defaultTypography.scale
326
+ ...state.typography,
327
+ fonts: currentFonts,
328
+ typeScaleOffset: clamp(action.offset, 0, 1)
344
329
  }
345
330
  };
346
331
  }
347
- case "SET_FONT_DEFAULT": {
332
+ case "SET_ROLE_WEIGHT": {
348
333
  const defaultTypography = DEFAULT_CONFIGURATOR_STATE.typography;
334
+ const currentFonts = state.typography?.fonts ?? defaultTypography.fonts;
349
335
  return {
350
336
  ...state,
351
337
  typography: {
352
- fonts: {
353
- mono: state.typography?.fonts.mono ?? defaultTypography.fonts.mono,
354
- display: state.typography?.fonts.display ?? defaultTypography.fonts.display,
355
- default: action.font
356
- },
357
- scale: state.typography?.scale ?? defaultTypography.scale
338
+ ...state.typography,
339
+ fonts: currentFonts,
340
+ roleWeights: {
341
+ ...state.typography?.roleWeights,
342
+ [action.role]: clamp(action.weight, 100, 900)
343
+ }
358
344
  }
359
345
  };
360
346
  }
@@ -455,34 +441,6 @@ var SPACING_PRESET_TO_BASE = {
455
441
  function roundnessToMultiplier(intensity) {
456
442
  return intensity * 2;
457
443
  }
458
- function computeTypographyScale(baseSize, ratio) {
459
- return {
460
- xs: Math.round(baseSize / ratio ** 2),
461
- sm: Math.round(baseSize / ratio),
462
- base: baseSize,
463
- md: Math.round(baseSize * ratio),
464
- lg: Math.round(baseSize * ratio ** 2),
465
- xl: Math.round(baseSize * ratio ** 3),
466
- xxl: Math.round(baseSize * ratio ** 4)
467
- };
468
- }
469
- var DEFAULT_FONTS = {
470
- mono: {
471
- type: "system",
472
- family: "ui-monospace",
473
- fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace"
474
- },
475
- display: {
476
- type: "system",
477
- family: "system-ui",
478
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
479
- },
480
- default: {
481
- type: "system",
482
- family: "system-ui",
483
- fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'
484
- }
485
- };
486
444
  var DEFAULT_ICONS = {
487
445
  variant: "rounded",
488
446
  // Material Design 3 aesthetic
@@ -546,15 +504,22 @@ function toThemeConfig(state) {
546
504
  xl: Math.round(12 * radiusMultiplier),
547
505
  pill: 999
548
506
  },
549
- typography: {
550
- fonts: state.typography?.fonts ?? DEFAULT_FONTS,
551
- scale: computeTypographyScale(
552
- state.typography?.scale.baseSize ?? 16,
553
- state.typography?.scale.ratio ?? 1.25
554
- ),
555
- lineHeight: { tight: 1.25, normal: 1.5, relaxed: 1.75 },
556
- fontWeight: { regular: 400, medium: 500, semibold: 600, bold: 700 }
557
- },
507
+ typography: (() => {
508
+ const roles = state.typography?.typeScaleOffset != null ? fonts.applyTypeScaleOffset(fonts.DEFAULT_ROLE_SCALES, state.typography.typeScaleOffset) : fonts.DEFAULT_ROLE_SCALES;
509
+ return {
510
+ fonts: {
511
+ main: fonts.migrateToFontSlot(state.typography?.fonts.main ?? state.typography?.fonts?.default, fonts.DEFAULT_FONT_SLOTS.main),
512
+ display: fonts.migrateToFontSlot(state.typography?.fonts.display, fonts.DEFAULT_FONT_SLOTS.display),
513
+ mono: fonts.migrateToFontSlot(state.typography?.fonts.mono, fonts.DEFAULT_FONT_SLOTS.mono),
514
+ currency: fonts.migrateToFontSlot(state.typography?.fonts.currency, fonts.DEFAULT_FONT_SLOTS.currency)
515
+ },
516
+ fontSizes: fonts.DEFAULT_FONT_SIZES,
517
+ lineHeights: fonts.DEFAULT_LINE_HEIGHTS,
518
+ roles,
519
+ breakpointRoles: fonts.computeBreakpointRoleScales(roles),
520
+ roleWeights: { ...fonts.ROLE_DEFAULT_WEIGHTS, ...state.typography?.roleWeights }
521
+ };
522
+ })(),
558
523
  icons: state.icons ?? DEFAULT_ICONS
559
524
  };
560
525
  }
@@ -1201,8 +1166,6 @@ function DesignPanel({ state, dispatch }) {
1201
1166
  const tokens = components.useTokens(1);
1202
1167
  const spacingPreset = state.spacing?.preset ?? "md";
1203
1168
  const intensity = state.roundness?.intensity ?? 0.5;
1204
- const baseSize = state.typography?.scale.baseSize ?? 16;
1205
- const ratio = state.typography?.scale.ratio ?? 1.25;
1206
1169
  const variant = state.icons?.variant ?? "rounded";
1207
1170
  const weight = state.icons?.weight ?? 400;
1208
1171
  return /* @__PURE__ */ React__default.default.createElement(components.Card, { elevation: 1, style: styles5.container }, /* @__PURE__ */ React__default.default.createElement(reactNative.Text, { style: [styles5.title, { color: newtone.srgbToHex(tokens.textPrimary.srgb) }] }, "Design System"), /* @__PURE__ */ React__default.default.createElement(reactNative.Text, { style: [styles5.subtitle, { color: newtone.srgbToHex(tokens.textSecondary.srgb) }] }, "Spacing"), /* @__PURE__ */ React__default.default.createElement(
@@ -1229,29 +1192,7 @@ function DesignPanel({ state, dispatch }) {
1229
1192
  label: "Intensity",
1230
1193
  showValue: true
1231
1194
  }
1232
- ), /* @__PURE__ */ React__default.default.createElement(reactNative.Text, { style: [styles5.subtitle, { color: newtone.srgbToHex(tokens.textSecondary.srgb) }] }, "Typography"), /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.row }, /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.flex }, /* @__PURE__ */ React__default.default.createElement(
1233
- components.Slider,
1234
- {
1235
- value: baseSize,
1236
- onValueChange: (v) => dispatch({ type: "SET_TYPOGRAPHY_BASE_SIZE", baseSize: v }),
1237
- min: 12,
1238
- max: 24,
1239
- step: 1,
1240
- label: "Base Size",
1241
- showValue: true
1242
- }
1243
- )), /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.flex }, /* @__PURE__ */ React__default.default.createElement(
1244
- components.Slider,
1245
- {
1246
- value: Math.round(ratio * 100),
1247
- onValueChange: (v) => dispatch({ type: "SET_TYPOGRAPHY_RATIO", ratio: v / 100 }),
1248
- min: 110,
1249
- max: 150,
1250
- step: 5,
1251
- label: "Scale Ratio",
1252
- showValue: true
1253
- }
1254
- ))), /* @__PURE__ */ React__default.default.createElement(reactNative.Text, { style: [styles5.subtitle, { color: newtone.srgbToHex(tokens.textSecondary.srgb) }] }, "Icons"), /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.row }, /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.flex }, /* @__PURE__ */ React__default.default.createElement(
1195
+ ), /* @__PURE__ */ React__default.default.createElement(reactNative.Text, { style: [styles5.subtitle, { color: newtone.srgbToHex(tokens.textSecondary.srgb) }] }, "Icons"), /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.row }, /* @__PURE__ */ React__default.default.createElement(reactNative.View, { style: styles5.flex }, /* @__PURE__ */ React__default.default.createElement(
1255
1196
  components.Select,
1256
1197
  {
1257
1198
  options: ICON_VARIANT_OPTIONS,