dsh-fonttune 0.7.2 → 0.7.4

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/lib/shared.cjs CHANGED
@@ -2959,19 +2959,36 @@ function codeSelector(hints) {
2959
2959
  CODE_SELECTOR = codeSelector(null);
2960
2960
 
2961
2961
  /**
2962
- * The dialog surface: DSH renders the conversation markdown in a CSS-module
2963
- * container whose class hashes per release (`_markdown_<hash>_…`), wrapped in a
2964
- * stable `[data-dss-prose]` container (measured on 0.1.5-rc.3: every markdown
2965
- * container on the page sits inside one). A class-substring match degrades
2966
- * safely — no match means the dialog follows the interface axis, the same
2967
- * behavior as an unknown token name — but it costs an attribute scan per
2968
- * element per rule, so the browser half prefers the stable wrapper when it can
2969
- * see one and falls back to the substring form otherwise.
2962
+ * The dialog surface, across two host generations.
2963
+ *
2964
+ * Up to DSH 0.2.1 the conversation markdown sat in a CSS-module container whose
2965
+ * class carried a `_markdown_` hash segment (`_markdown_<hash>_…`), wrapped in
2966
+ * a stable `[data-dss-prose]` container. DSH 0.2.2 dropped both: the class is
2967
+ * now `<hash>_root` and the prose wrapper is gone, which left every dialog rule
2968
+ * matching zero elements and the whole conversation axis silently inert.
2969
+ *
2970
+ * What 0.2.2 does still expose is the content container
2971
+ * `[data-conversation-content]`, so the markdown block elements inside it
2972
+ * stand in for the scope. A class-substring match degrades safely — no match
2973
+ * means the dialog follows the interface axis, the same behavior as an unknown
2974
+ * token name — but it costs an attribute scan per element per rule, so the
2975
+ * browser half prefers the stable wrapper when it can see one and falls back to
2976
+ * the element list otherwise.
2970
2977
  */
2978
+ var MARKDOWN_BLOCK_ELEMENTS = "p,li,h1,h2,h3,h4,h5,h6,blockquote,td,th,dt,dd";
2979
+
2971
2980
  var MARKDOWN_SELECTOR =
2972
- '[class*="_markdown_" i]' +
2981
+ '[data-dss-prose]' +
2982
+ CODE_EXCLUDES +
2983
+ ',[data-dss-prose] *' +
2984
+ CODE_EXCLUDES +
2985
+ ',[class*="_markdown_" i]' +
2973
2986
  CODE_EXCLUDES +
2974
2987
  ',[class*="_markdown_" i] *' +
2988
+ CODE_EXCLUDES +
2989
+ ',[data-conversation-content] :where(' +
2990
+ MARKDOWN_BLOCK_ELEMENTS +
2991
+ ')' +
2975
2992
  CODE_EXCLUDES;
2976
2993
 
2977
2994
  /**
@@ -3237,6 +3254,294 @@ function ceilTo(value, step) {
3237
3254
  return Math.ceil(value / step) * step;
3238
3255
  }
3239
3256
 
3257
+ /**
3258
+ * How far apart two families may land on one notch before the stack refuses it.
3259
+ *
3260
+ * Measured on the reporter's pair (issue #4): one 100-weight notch adds +21.5%
3261
+ * ink to the Latin family and +23.9% to the Chinese one — 2.4 points apart, which
3262
+ * no reader notices. One 200-weight notch adds +44% and +51% — 7.4 points apart,
3263
+ * and that is the reported "one side suits, the other is too heavy". Five points
3264
+ * is the budget between those two observations.
3265
+ */
3266
+ var INK_BALANCE_SPREAD = 0.05;
3267
+
3268
+ /**
3269
+ * How far apart a pair may land when the strict budget would leave no control.
3270
+ *
3271
+ * Measured on the reporter's pair (issue #4): going one notch LIGHTER, the Latin
3272
+ * family loses 29.7% of its ink and the Chinese one 17.9% — 11.9 points apart, and
3273
+ * no finer notch makes it better, because the two families simply space their faces
3274
+ * differently. Under the strict budget the reader would get a weight control that
3275
+ * cannot go lighter at all (two positions). The wider budget is what keeps that
3276
+ * physical pair usable, and it is only consulted when the strict one is: a stack
3277
+ * that has four even positions never sees it.
3278
+ */
3279
+ var INK_BALANCE_SPREAD_WIDE = 0.15;
3280
+
3281
+ /** How many notches the evenness walk looks at, one way. */
3282
+ var WEIGHT_MAX_POSITIONS = 24;
3283
+
3284
+ /**
3285
+ * The least ink one notch has to add before a position is worth having.
3286
+ *
3287
+ * This is the bar `weightProfileFrom` already measured on this host: a 200-weight
3288
+ * step is +30% ink and a 100-weight step +16%, and 100 was not enough — a reader
3289
+ * could not see it. Five per cent would put a variable family's stack at twenty-odd
3290
+ * notches that each move a little (measured live: 29 positions of +6%), which is the
3291
+ * dead-control the coarse step exists to avoid. Fifteen keeps every pair the faces
3292
+ * do allow (the reported one tops out at +19%/+22%) and stops there.
3293
+ */
3294
+ var INK_BALANCE_STEP = 0.15;
3295
+
3296
+ /**
3297
+ * One family's ink at one weight.
3298
+ *
3299
+ * A family answers through `inkOf`, the sampler its own measurement already uses;
3300
+ * a weight it cannot measure — or a family that cannot be measured at all — answers
3301
+ * null and is left out of a comparison instead of counting as a zero.
3302
+ * @param {Object} entry - one measured family.
3303
+ * @param {number} weight - CSS weight.
3304
+ * @returns {number|null} the ink, or null when there is no measurement.
3305
+ */
3306
+ function entryInk(entry, weight) {
3307
+ if (entry === null || typeof entry !== "object") return null;
3308
+ if (typeof entry.inkOf !== "function") return null;
3309
+ var ink = null;
3310
+ try {
3311
+ ink = entry.inkOf(weight);
3312
+ } catch (error) {
3313
+ return null;
3314
+ }
3315
+ ink = Number(ink);
3316
+ if (!isFinite(ink) || ink <= 0) return null;
3317
+ return ink;
3318
+ }
3319
+
3320
+ /**
3321
+ * How much moving from one weight to another changes each family's ink.
3322
+ *
3323
+ * The share is relative to the family's OWN ink at `from`, so two families that
3324
+ * start out different sizes are still comparable: +20% means the same thing for
3325
+ * both. Families that cannot be measured on both sides are left out.
3326
+ * @param {Array<Object>} entries - the measured families.
3327
+ * @param {number} from - the weight the reader is at.
3328
+ * @param {number} to - the weight being compared.
3329
+ * @returns {number[]|null} the relative changes, or null when fewer than two
3330
+ * families can be measured.
3331
+ */
3332
+ function inkShares(entries, from, to) {
3333
+ var shares = [];
3334
+ for (var index = 0; index < entries.length; index += 1) {
3335
+ var before = entryInk(entries[index], from);
3336
+ var after = entryInk(entries[index], to);
3337
+ if (before === null || after === null) continue;
3338
+ shares.push((after - before) / before);
3339
+ }
3340
+ return shares.length < 2 ? null : shares;
3341
+ }
3342
+
3343
+ /**
3344
+ * How far apart the families land, and how little the quietest one moved.
3345
+ * @param {number[]} shares - one relative change per family.
3346
+ * @returns {{spread: number, smallest: number}} `spread` is the signed range, so
3347
+ * families moving in opposite directions count as far apart.
3348
+ */
3349
+ function shareSpread(shares) {
3350
+ var least = shares[0];
3351
+ var most = shares[0];
3352
+ var smallest = Math.abs(shares[0]);
3353
+ for (var index = 1; index < shares.length; index += 1) {
3354
+ if (shares[index] < least) least = shares[index];
3355
+ if (shares[index] > most) most = shares[index];
3356
+ var size = Math.abs(shares[index]);
3357
+ if (size < smallest) smallest = size;
3358
+ }
3359
+ return { spread: most - least, smallest: smallest };
3360
+ }
3361
+
3362
+ /**
3363
+ * The evenness verdict for one move of the stack.
3364
+ * @param {Array<Object>} entries - the measured families.
3365
+ * @param {number} from - the weight the move starts at.
3366
+ * @param {number} to - the weight it ends at.
3367
+ * @returns {{spread: number, smallest: number}|null} the verdict, or null when it
3368
+ * cannot be measured.
3369
+ */
3370
+ function evennessOf(entries, from, to) {
3371
+ var shares = inkShares(entries, from, to);
3372
+ if (shares === null) return null;
3373
+ return shareSpread(shares);
3374
+ }
3375
+
3376
+ /** Is one move of the stack both visible and even? */
3377
+ function moveIsEven(verdict, spread) {
3378
+ return verdict !== null && verdict.smallest >= INK_BALANCE_STEP && verdict.spread <= spread;
3379
+ }
3380
+
3381
+ /**
3382
+ * The shape a stack of families can follow together, chosen for EVENNESS.
3383
+ *
3384
+ * Issue #4 is not about the range: it is about two families being moved by one
3385
+ * offset and landing on faces that are not the same distance apart. The test is
3386
+ * therefore walked outwards from the neutral position, one notch at a time, and a
3387
+ * notch only survives when BOTH hold:
3388
+ * - every family's ink changes by at least `INK_BALANCE_STEP` (the notch is
3389
+ * visible), and
3390
+ * - the families land within `INK_BALANCE_SPREAD` of each other, measured both for
3391
+ * that one notch and for the whole way back to the neutral position — a stack
3392
+ * can be even notch by notch and still drift apart after two of them.
3393
+ *
3394
+ * The walk is what removes the synthetic-bold step without ever having to ask the
3395
+ * browser whether a weight is drawn or faked: above its last real face a family is
3396
+ * stroked thicker by the browser, which adds a much larger share of ink than a drawn
3397
+ * face does — so the notch where one family jumps and the other does not simply
3398
+ * fails the budget and the range stops in front of it.
3399
+ *
3400
+ * Among the shapes that survive, the one with the MOST positions wins: the visible
3401
+ * floor above is what makes a finer notch worth having, and more positions is more
3402
+ * control. (A single family is not put through this at all — it keeps the coarse
3403
+ * shape `weightProfileFrom` measured for it.)
3404
+ * @param {Array<{min: number, max: number, step: number, inkOf?: Function}>} entries
3405
+ * one record per measured family.
3406
+ * @param {number} base - the weight the offset is added to (body text).
3407
+ * @param {number} low - the lowest offset every family can express.
3408
+ * @param {number} high - the highest offset every family can express.
3409
+ * @returns {{min: number, max: number, step: number}|null} the shape, or null when
3410
+ * no step leaves the stack two positions to move between.
3411
+ */
3412
+ function balancedStackShape(entries, base, low, high, spread) {
3413
+ var budget = typeof spread === "number" && spread > 0 ? spread : INK_BALANCE_SPREAD;
3414
+ var best = null;
3415
+ var bestCount = 1;
3416
+ var bestScore = Infinity;
3417
+ for (var index = 0; index < WEIGHT_STEP_CANDIDATES.length; index += 1) {
3418
+ var step = WEIGHT_STEP_CANDIDATES[index];
3419
+ if (!(step > 0)) continue;
3420
+ var up = 0;
3421
+ var down = 0;
3422
+ // A walk is bounded: no useful shape has more than a couple of dozen
3423
+ // positions, and an unbounded one on a one-unit grid would cost hundreds of
3424
+ // canvas renders on the very first measurement.
3425
+ var limit = step * WEIGHT_MAX_POSITIONS;
3426
+ for (var position = step; position <= high && position <= limit; position += step) {
3427
+ if (!moveIsEven(evennessOf(entries, base + position - step, base + position), budget)) break;
3428
+ if (!moveIsEven(evennessOf(entries, base, base + position), budget)) break;
3429
+ up = position;
3430
+ }
3431
+ for (var back = step; back <= -low && back <= limit; back += step) {
3432
+ if (!moveIsEven(evennessOf(entries, base - back + step, base - back), budget)) break;
3433
+ if (!moveIsEven(evennessOf(entries, base, base - back), budget)) break;
3434
+ down = back;
3435
+ }
3436
+ var count = (up + down) / step + 1;
3437
+ if (count < 2) continue;
3438
+ // How close the two families are on one notch from the neutral position: a tie
3439
+ // between two shapes that move the stack over the same number of positions.
3440
+ var headroom = evennessOf(entries, base, base + step);
3441
+ if (headroom === null) headroom = evennessOf(entries, base, base - step);
3442
+ var score = headroom === null ? Infinity : headroom.spread;
3443
+ if (count > bestCount || (count === bestCount && score < bestScore)) {
3444
+ // -0 would read as a different number to a strict comparison.
3445
+ best = { min: down === 0 ? 0 : -down, max: up, step: step };
3446
+ bestCount = count;
3447
+ bestScore = score;
3448
+ }
3449
+ }
3450
+ return best;
3451
+ }
3452
+
3453
+ /**
3454
+ * One slider shape for a stack whose text can land on more than one family.
3455
+ *
3456
+ * A reader sets ONE offset; the browser then renders English with the first
3457
+ * family and Chinese with the fallback, each snapping that same requested value
3458
+ * to its own faces. When the fallback ships three faces and the primary is a
3459
+ * variable font, a step measured on the primary alone leaves the fallback
3460
+ * unchanged on most notches — the reported "one side suits, the other is too
3461
+ * heavy or too light" (issue #4: Inclusive Sans beside a three-face CJK family).
3462
+ *
3463
+ * The combined shape keeps every family moving on every notch, but the notch is
3464
+ * chosen for EVENNESS (see `balancedStackShape`): each family has to change by a
3465
+ * comparable share of its own ink, and the stack has to stay together over the
3466
+ * whole length of the range. Families that can report their ink (`inkOf`) get that
3467
+ * shape; a stack measured without a canvas keeps the plain shared-multiple shape,
3468
+ * which is also what a single family gets.
3469
+ * @param {Array<{min: number, max: number, step: number, inkOf?: Function}|null>} profiles
3470
+ * one shape per family.
3471
+ * @param {{base?: number}} [options] `base` is the weight the offset is added to
3472
+ * (body text); it anchors the ink comparison.
3473
+ * @returns {{min: number, max: number, step: number}|null} the combined shape, or
3474
+ * null when nothing usable was measured.
3475
+ */
3476
+ function combineWeightProfiles(profiles, options) {
3477
+ var list = [];
3478
+ if (Array.isArray(profiles)) {
3479
+ for (var index = 0; index < profiles.length; index += 1) {
3480
+ var entry = profiles[index];
3481
+ if (entry === null || typeof entry !== "object") continue;
3482
+ if (!isFinite(entry.min) || !isFinite(entry.max) || !isFinite(entry.step)) continue;
3483
+ if (!(entry.step > 0)) continue;
3484
+ list.push(entry);
3485
+ }
3486
+ }
3487
+ if (list.length === 0) return null;
3488
+ if (list.length === 1) return { min: list[0].min, max: list[0].max, step: list[0].step };
3489
+ var step = list[0].step;
3490
+ for (var other = 1; other < list.length; other += 1) {
3491
+ step = commonStep(step, list[other].step);
3492
+ }
3493
+ var low = list[0].min;
3494
+ var high = list[0].max;
3495
+ for (var more = 1; more < list.length; more += 1) {
3496
+ low = Math.max(low, list[more].min);
3497
+ high = Math.min(high, list[more].max);
3498
+ }
3499
+ var settings = options === null || typeof options !== "object" ? {} : options;
3500
+ var base = isFinite(settings.base) ? Number(settings.base) : WEIGHT_BASE;
3501
+ // Every family that can report ink is put through the evenness walk; a stack whose
3502
+ // canvas could not answer keeps the plain shared-multiple shape.
3503
+ var measured = false;
3504
+ for (var scan = 0; scan < list.length; scan += 1) {
3505
+ if (typeof list[scan].inkOf === "function") measured = true;
3506
+ }
3507
+ if (measured) {
3508
+ var even = balancedStackShape(list, base, low, high);
3509
+ var positions = even === null ? 0 : (even.max - even.min) / even.step + 1;
3510
+ if (positions >= 3) return even;
3511
+ // The pair's own faces are spaced so unevenly that the strict budget leaves
3512
+ // no control; the wider one is what keeps a lighter position reachable.
3513
+ var relaxed = balancedStackShape(list, base, low, high, INK_BALANCE_SPREAD_WIDE);
3514
+ var relaxedPositions = relaxed === null ? 0 : (relaxed.max - relaxed.min) / relaxed.step + 1;
3515
+ if (relaxedPositions > positions) return relaxed;
3516
+ if (even !== null) return even;
3517
+ }
3518
+ var onGrid = { min: ceilTo(low, step), max: floorTo(high, step) };
3519
+ if (onGrid.max >= onGrid.min) return { min: onGrid.min, max: onGrid.max, step: step };
3520
+ var widest = list[0];
3521
+ for (var alt = 1; alt < list.length; alt += 1) {
3522
+ if (list[alt].max - list[alt].min > widest.max - widest.min) widest = list[alt];
3523
+ }
3524
+ return { min: widest.min, max: widest.max, step: widest.step };
3525
+ }
3526
+
3527
+ /**
3528
+ * The smallest candidate step that is a whole multiple of both inputs.
3529
+ *
3530
+ * Profiles come from one candidate list, so a shared multiple usually exists
3531
+ * there; two steps that share none fall back to the coarser one, which still
3532
+ * moves the coarser family on every notch.
3533
+ * @param {number} a - one step.
3534
+ * @param {number} b - another step.
3535
+ * @returns {number} the combined step.
3536
+ */
3537
+ function commonStep(a, b) {
3538
+ for (var index = 0; index < WEIGHT_STEP_CANDIDATES.length; index += 1) {
3539
+ var candidate = WEIGHT_STEP_CANDIDATES[index];
3540
+ if (candidate % a === 0 && candidate % b === 0) return candidate;
3541
+ }
3542
+ return Math.max(a, b);
3543
+ }
3544
+
3240
3545
  /**
3241
3546
  * Does every position of `[min..max]` in `step` increments render differently?
3242
3547
  *
@@ -4820,6 +5125,16 @@ var shared = {
4820
5125
  WEIGHT_CSS_MIN: WEIGHT_CSS_MIN,
4821
5126
  WEIGHT_CSS_MAX: WEIGHT_CSS_MAX,
4822
5127
  weightProfileFrom: weightProfileFrom,
5128
+ combineWeightProfiles: combineWeightProfiles,
5129
+ balancedStackShape: balancedStackShape,
5130
+ evennessOf: evennessOf,
5131
+ INK_BALANCE_SPREAD: INK_BALANCE_SPREAD,
5132
+ INK_BALANCE_STEP: INK_BALANCE_STEP,
5133
+ INK_BALANCE_SPREAD_WIDE: INK_BALANCE_SPREAD_WIDE,
5134
+ WEIGHT_PROBE_LOW: WEIGHT_PROBE_LOW,
5135
+ WEIGHT_PROBE_HIGH: WEIGHT_PROBE_HIGH,
5136
+ WEIGHT_PROBE_STEP: WEIGHT_PROBE_STEP,
5137
+ GENERIC_FAMILIES: GENERIC_FAMILIES,
4823
5138
  weightStepRange: weightStepRange,
4824
5139
  isShorthandName: isShorthandName,
4825
5140
  isScaledToken: isScaledToken,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-fonttune",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Font plugin for the DeepSeek Harness Web GUI: the conversation gets its own font, size, line height and weight, the interface font and weight follow it, code keeps its own axis with ligature control, and whole setups save as presets.",
5
5
  "type": "module",
6
6
  "icon": "icon.svg",