@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
package/dist/index.js
CHANGED
|
@@ -196,12 +196,13 @@ async function measureFontCalibrations(fonts) {
|
|
|
196
196
|
const calibrations = {};
|
|
197
197
|
const seen = /* @__PURE__ */ new Set();
|
|
198
198
|
for (const slot of Object.values(fonts)) {
|
|
199
|
+
if (!slot?.config) continue;
|
|
199
200
|
const { family, fallback } = slot.config;
|
|
200
201
|
if (seen.has(family)) continue;
|
|
201
202
|
seen.add(family);
|
|
202
203
|
const ratio = await measureAvgCharWidth(
|
|
203
204
|
family,
|
|
204
|
-
slot.weights
|
|
205
|
+
slot.weights?.regular ?? 400,
|
|
205
206
|
fallback
|
|
206
207
|
);
|
|
207
208
|
calibrations[family] = ratio;
|
|
@@ -219,6 +220,7 @@ async function lookupFontMetrics(fonts, manifestUrl) {
|
|
|
219
220
|
const result = {};
|
|
220
221
|
const seen = /* @__PURE__ */ new Set();
|
|
221
222
|
for (const slot of Object.values(fonts)) {
|
|
223
|
+
if (!slot?.config) continue;
|
|
222
224
|
const family = slot.config.family;
|
|
223
225
|
if (seen.has(family)) continue;
|
|
224
226
|
seen.add(family);
|
|
@@ -471,24 +473,37 @@ function useEditorState({
|
|
|
471
473
|
const handlePublish = useCallback(async () => {
|
|
472
474
|
if (debounceRef.current) clearTimeout(debounceRef.current);
|
|
473
475
|
setPublishing(true);
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
476
|
+
const timeout = new Promise(
|
|
477
|
+
(_, reject) => setTimeout(() => reject(new Error("Publish timed out after 15 s")), 15e3)
|
|
478
|
+
);
|
|
479
|
+
try {
|
|
480
|
+
await Promise.race([
|
|
481
|
+
(async () => {
|
|
482
|
+
const currentState = latestStateRef.current;
|
|
483
|
+
const updatedPresets = publishActivePreset(currentState);
|
|
484
|
+
const [calibrations, fontMetrics] = await Promise.all([
|
|
485
|
+
measureFontCalibrations(currentState.typography?.fonts),
|
|
486
|
+
lookupFontMetrics(currentState.typography?.fonts, manifestUrl)
|
|
487
|
+
]);
|
|
488
|
+
const { error } = await persistence.onPublish({
|
|
489
|
+
state: currentState,
|
|
490
|
+
presets: updatedPresets,
|
|
491
|
+
activePresetId,
|
|
492
|
+
calibrations,
|
|
493
|
+
fontMetrics
|
|
494
|
+
});
|
|
495
|
+
if (!error) {
|
|
496
|
+
setSaveStatus("saved");
|
|
497
|
+
setIsPublished(true);
|
|
498
|
+
}
|
|
499
|
+
})(),
|
|
500
|
+
timeout
|
|
501
|
+
]);
|
|
502
|
+
} catch (err) {
|
|
503
|
+
console.error("[Editor] Publish failed:", err);
|
|
504
|
+
} finally {
|
|
505
|
+
setPublishing(false);
|
|
490
506
|
}
|
|
491
|
-
setPublishing(false);
|
|
492
507
|
}, [activePresetId, publishActivePreset, persistence, manifestUrl]);
|
|
493
508
|
useEffect(() => {
|
|
494
509
|
const handleBeforeUnload = (e) => {
|
|
@@ -2013,7 +2028,7 @@ function IconsSection({ state, dispatch }) {
|
|
|
2013
2028
|
] });
|
|
2014
2029
|
}
|
|
2015
2030
|
|
|
2016
|
-
// ../../../newtone-fonts/dist/
|
|
2031
|
+
// ../../../newtone-fonts/dist/defaults.js
|
|
2017
2032
|
var ROLE_DEFAULT_WEIGHTS = {
|
|
2018
2033
|
headline: 700,
|
|
2019
2034
|
title: 700,
|
|
@@ -2028,20 +2043,28 @@ var BREAKPOINT_ROLE_SCALE = {
|
|
|
2028
2043
|
md: { headline: 0.83, title: 0.88, heading: 0.92, subheading: 0.95, body: 0.97, label: 0.98, caption: 1 },
|
|
2029
2044
|
lg: { headline: 1, title: 1, heading: 1, subheading: 1, body: 1, label: 1, caption: 1 }
|
|
2030
2045
|
};
|
|
2046
|
+
|
|
2047
|
+
// ../../../newtone-fonts/dist/scale/breakpoints.js
|
|
2031
2048
|
function scaleRoleStep(step, scale) {
|
|
2032
2049
|
return {
|
|
2033
2050
|
fontSize: Math.round(step.fontSize * scale),
|
|
2034
2051
|
lineHeight: Math.round(step.lineHeight * scale / 4) * 4
|
|
2035
2052
|
};
|
|
2036
2053
|
}
|
|
2054
|
+
|
|
2055
|
+
// ../../../newtone-fonts/dist/catalog.js
|
|
2037
2056
|
var SYSTEM_FONTS = [
|
|
2038
2057
|
{ family: "system-ui", category: "sans-serif", fallback: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif' },
|
|
2039
2058
|
{ family: "ui-serif", category: "serif", fallback: '"Iowan Old Style", "Apple Garamond", Baskerville, Georgia, serif' },
|
|
2040
2059
|
{ family: "ui-monospace", category: "monospace", fallback: "SFMono-Regular, Menlo, Monaco, Consolas, monospace" }
|
|
2041
2060
|
];
|
|
2061
|
+
|
|
2062
|
+
// ../../../newtone-fonts/dist/responsive/scoring.js
|
|
2042
2063
|
function scoreLineBreaks(lineWidths, containerWidth) {
|
|
2043
|
-
if (lineWidths.length <= 1)
|
|
2044
|
-
|
|
2064
|
+
if (lineWidths.length <= 1)
|
|
2065
|
+
return 1;
|
|
2066
|
+
if (containerWidth <= 0)
|
|
2067
|
+
return 0;
|
|
2045
2068
|
const lineCount = lineWidths.length;
|
|
2046
2069
|
const lastLineWidth = lineWidths[lineCount - 1];
|
|
2047
2070
|
const lastLineRatio = Math.max(0, Math.min(1, lastLineWidth / containerWidth));
|
|
@@ -2072,6 +2095,8 @@ function scoreLineBreaks(lineWidths, containerWidth) {
|
|
|
2072
2095
|
const RAG_WEIGHT = 0.35;
|
|
2073
2096
|
return WIDOW_WEIGHT * widowScore + RAG_WEIGHT * ragScore;
|
|
2074
2097
|
}
|
|
2098
|
+
|
|
2099
|
+
// ../../../newtone-fonts/dist/responsive/resolve.js
|
|
2075
2100
|
function estimateLineWidths(characterCount, containerWidth, fontSize, avgCharWidthRatio = 0.55) {
|
|
2076
2101
|
const avgCharWidth = fontSize * avgCharWidthRatio;
|
|
2077
2102
|
const totalWidth = characterCount * avgCharWidth;
|
|
@@ -2114,7 +2139,8 @@ function resolveResponsiveSize(config, roleScales, measurement, calibrations) {
|
|
|
2114
2139
|
bestScore = score;
|
|
2115
2140
|
bestFontSize = fs;
|
|
2116
2141
|
}
|
|
2117
|
-
if (score >= 0.95)
|
|
2142
|
+
if (score >= 0.95)
|
|
2143
|
+
break;
|
|
2118
2144
|
}
|
|
2119
2145
|
return {
|
|
2120
2146
|
fontSize: bestFontSize,
|