@newtonedev/editor 0.1.7 → 0.1.9
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/hooks/useEditorState.d.ts.map +1 -1
- package/dist/index.cjs +48 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +48 -22
- package/dist/index.js.map +1 -1
- package/dist/utils/lookupFontMetrics.d.ts.map +1 -1
- package/dist/utils/measureFonts.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/hooks/useEditorState.ts +34 -19
- package/src/utils/lookupFontMetrics.ts +1 -0
- package/src/utils/measureFonts.ts +2 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEditorState.d.ts","sourceRoot":"","sources":["../../src/hooks/useEditorState.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EACV,WAAW,EACX,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAIlB,UAAU,qBAAqB;IAC7B,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,kBAAkB,EAAE,OAAO,CAAC;IACrC,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAC;IACvC,QAAQ,CAAC,wBAAwB,EAAE,MAAM,GAAG,IAAI,CAAC;IACjD,QAAQ,CAAC,YAAY,EAAE,iBAAiB,CAAC;IACzC,QAAQ,CAAC,WAAW,EAAE,iBAAiB,CAAC;IACxC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,IAAI,CAAC;IAClD,QAAQ,CAAC,kBAAkB,CAAC,EAAE,WAAW,CAAC;IAC1C,QAAQ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AAc,CAAC,EAC7B,YAAY,EACZ,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,wBAAwB,EACxB,YAAY,EACZ,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,WAAW,GACZ,EAAE,qBAAqB;;;;;;;;;gCAsON,iBAAiB;;;;2CA3GxB,WAAW;8CAsBN,MAAM;8CA8BN,MAAM;2CAwFX,SAAS;;;;;4CA3DL,MAAM,SAAS,OAAO;;;;;;;;;;;;;;;EAkMpC"}
|
package/dist/index.cjs
CHANGED
|
@@ -198,12 +198,13 @@ async function measureFontCalibrations(fonts) {
|
|
|
198
198
|
const calibrations = {};
|
|
199
199
|
const seen = /* @__PURE__ */ new Set();
|
|
200
200
|
for (const slot of Object.values(fonts)) {
|
|
201
|
+
if (!slot?.config) continue;
|
|
201
202
|
const { family, fallback } = slot.config;
|
|
202
203
|
if (seen.has(family)) continue;
|
|
203
204
|
seen.add(family);
|
|
204
205
|
const ratio = await components.measureAvgCharWidth(
|
|
205
206
|
family,
|
|
206
|
-
slot.weights
|
|
207
|
+
slot.weights?.regular ?? 400,
|
|
207
208
|
fallback
|
|
208
209
|
);
|
|
209
210
|
calibrations[family] = ratio;
|
|
@@ -221,6 +222,7 @@ async function lookupFontMetrics(fonts, manifestUrl) {
|
|
|
221
222
|
const result = {};
|
|
222
223
|
const seen = /* @__PURE__ */ new Set();
|
|
223
224
|
for (const slot of Object.values(fonts)) {
|
|
225
|
+
if (!slot?.config) continue;
|
|
224
226
|
const family = slot.config.family;
|
|
225
227
|
if (seen.has(family)) continue;
|
|
226
228
|
seen.add(family);
|
|
@@ -473,24 +475,37 @@ function useEditorState({
|
|
|
473
475
|
const handlePublish = react.useCallback(async () => {
|
|
474
476
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
475
477
|
setPublishing(true);
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
478
|
+
const timeout = new Promise(
|
|
479
|
+
(_, reject) => setTimeout(() => reject(new Error("Publish timed out after 15 s")), 15e3)
|
|
480
|
+
);
|
|
481
|
+
try {
|
|
482
|
+
await Promise.race([
|
|
483
|
+
(async () => {
|
|
484
|
+
const currentState = latestStateRef.current;
|
|
485
|
+
const updatedPresets = publishActivePreset(currentState);
|
|
486
|
+
const [calibrations, fontMetrics] = await Promise.all([
|
|
487
|
+
measureFontCalibrations(currentState.typography?.fonts),
|
|
488
|
+
lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
|
|
489
|
+
]);
|
|
490
|
+
const { error } = await persistence.onPublish({
|
|
491
|
+
state: currentState,
|
|
492
|
+
presets: updatedPresets,
|
|
493
|
+
activePresetId,
|
|
494
|
+
calibrations,
|
|
495
|
+
fontMetrics
|
|
496
|
+
});
|
|
497
|
+
if (!error) {
|
|
498
|
+
setSaveStatus("saved");
|
|
499
|
+
setIsPublished(true);
|
|
500
|
+
}
|
|
501
|
+
})(),
|
|
502
|
+
timeout
|
|
503
|
+
]);
|
|
504
|
+
} catch (err) {
|
|
505
|
+
console.error("[Editor] Publish failed:", err);
|
|
506
|
+
} finally {
|
|
507
|
+
setPublishing(false);
|
|
492
508
|
}
|
|
493
|
-
setPublishing(false);
|
|
494
509
|
}, [activePresetId, publishActivePreset, persistence, manifestUrl]);
|
|
495
510
|
react.useEffect(() => {
|
|
496
511
|
const handleBeforeUnload = (e) => {
|
|
@@ -2015,7 +2030,7 @@ function IconsSection({ state, dispatch }) {
|
|
|
2015
2030
|
] });
|
|
2016
2031
|
}
|
|
2017
2032
|
|
|
2018
|
-
// ../../../newtone-fonts/dist/
|
|
2033
|
+
// ../../../newtone-fonts/dist/defaults.js
|
|
2019
2034
|
var ROLE_DEFAULT_WEIGHTS = {
|
|
2020
2035
|
headline: 700,
|
|
2021
2036
|
title: 700,
|
|
@@ -2030,20 +2045,28 @@ var BREAKPOINT_ROLE_SCALE = {
|
|
|
2030
2045
|
md: { headline: 0.83, title: 0.88, heading: 0.92, subheading: 0.95, body: 0.97, label: 0.98, caption: 1 },
|
|
2031
2046
|
lg: { headline: 1, title: 1, heading: 1, subheading: 1, body: 1, label: 1, caption: 1 }
|
|
2032
2047
|
};
|
|
2048
|
+
|
|
2049
|
+
// ../../../newtone-fonts/dist/scale/breakpoints.js
|
|
2033
2050
|
function scaleRoleStep(step, scale) {
|
|
2034
2051
|
return {
|
|
2035
2052
|
fontSize: Math.round(step.fontSize * scale),
|
|
2036
2053
|
lineHeight: Math.round(step.lineHeight * scale / 4) * 4
|
|
2037
2054
|
};
|
|
2038
2055
|
}
|
|
2056
|
+
|
|
2057
|
+
// ../../../newtone-fonts/dist/catalog.js
|
|
2039
2058
|
var SYSTEM_FONTS = [
|
|
2040
2059
|
{ family: "system-ui", category: "sans-serif", fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif' },
|
|
2041
2060
|
{ family: "ui-serif", category: "serif", fallback: '"Iowan Old Style", "Apple Garamond", Baskerville, Georgia, serif' },
|
|
2042
2061
|
{ family: "ui-monospace", category: "monospace", fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace" }
|
|
2043
2062
|
];
|
|
2063
|
+
|
|
2064
|
+
// ../../../newtone-fonts/dist/responsive/scoring.js
|
|
2044
2065
|
function scoreLineBreaks(lineWidths, containerWidth) {
|
|
2045
|
-
if (lineWidths.length <= 1)
|
|
2046
|
-
|
|
2066
|
+
if (lineWidths.length <= 1)
|
|
2067
|
+
return 1;
|
|
2068
|
+
if (containerWidth <= 0)
|
|
2069
|
+
return 0;
|
|
2047
2070
|
const lineCount = lineWidths.length;
|
|
2048
2071
|
const lastLineWidth = lineWidths[lineCount - 1];
|
|
2049
2072
|
const lastLineRatio = Math.max(0, Math.min(1, lastLineWidth / containerWidth));
|
|
@@ -2074,6 +2097,8 @@ function scoreLineBreaks(lineWidths, containerWidth) {
|
|
|
2074
2097
|
const RAG_WEIGHT = 0.35;
|
|
2075
2098
|
return WIDOW_WEIGHT * widowScore + RAG_WEIGHT * ragScore;
|
|
2076
2099
|
}
|
|
2100
|
+
|
|
2101
|
+
// ../../../newtone-fonts/dist/responsive/resolve.js
|
|
2077
2102
|
function estimateLineWidths(characterCount, containerWidth, fontSize, avgCharWidthRatio = 0.55) {
|
|
2078
2103
|
const avgCharWidth = fontSize * avgCharWidthRatio;
|
|
2079
2104
|
const totalWidth = characterCount * avgCharWidth;
|
|
@@ -2116,7 +2141,8 @@ function resolveResponsiveSize(config, roleScales, measurement, calibrations) {
|
|
|
2116
2141
|
bestScore = score;
|
|
2117
2142
|
bestFontSize = fs;
|
|
2118
2143
|
}
|
|
2119
|
-
if (score >= 0.95)
|
|
2144
|
+
if (score >= 0.95)
|
|
2145
|
+
break;
|
|
2120
2146
|
}
|
|
2121
2147
|
return {
|
|
2122
2148
|
fontSize: bestFontSize,
|