pdfjs-reader-core 0.4.3 → 0.5.1

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
@@ -12996,8 +12996,6 @@ var PAPER = "#faf6ec";
12996
12996
  var ACCENT = "#b04a1a";
12997
12997
  var ACCENT_SOFT = "rgba(176, 74, 26, 0.18)";
12998
12998
  var ACCENT_GLOW = "rgba(176, 74, 26, 0.35)";
12999
- var MARKER = "#e6b422";
13000
- var MARKER_SOFT = "rgba(230, 180, 34, 0.38)";
13001
12999
  var SERIF = "'Iowan Old Style', 'Palatino Linotype', Palatino, 'Book Antiqua', 'EB Garamond', 'Hoefler Text', Georgia, serif";
13002
13000
  var EASE_OUT_EXPO = [0.22, 1, 0.36, 1];
13003
13001
 
@@ -13285,17 +13283,17 @@ function AnimatedUnderline({ bbox, action }) {
13285
13283
  import { useId as useId2 } from "react";
13286
13284
  import { motion as motion4 } from "framer-motion";
13287
13285
  import { jsx as jsx44, jsxs as jsxs37 } from "react/jsx-runtime";
13286
+ var WASH = "rgba(230, 180, 34, 0.22)";
13288
13287
  function AnimatedHighlight({ bbox, action }) {
13289
13288
  const [x1, y1, x2, y2] = bbox;
13290
13289
  const h = Math.max(1, y2 - y1);
13291
13290
  const bleed = Math.min(4, h * 0.12);
13292
13291
  const yTop = y1 - bleed;
13293
13292
  const yBot = y2 + bleed;
13294
- const height = yBot - yTop;
13295
13293
  const duration = action.draw_duration_ms / 1e3;
13296
13294
  const filterId = useId2();
13297
- const fill = action.color && action.color !== "rgba(250, 204, 21, 0.35)" && action.color !== "rgba(250,204,21,0.35)" ? action.color : MARKER_SOFT;
13298
- const inner = action.color && action.color !== "rgba(250, 204, 21, 0.35)" && action.color !== "rgba(250,204,21,0.35)" ? action.color : MARKER;
13295
+ const isDefaultColour = !action.color || action.color === "rgba(250, 204, 21, 0.35)" || action.color === "rgba(250,204,21,0.35)";
13296
+ const fill = isDefaultColour ? WASH : action.color;
13299
13297
  const taper = Math.min(6, h * 0.2);
13300
13298
  const pathD = `
13301
13299
  M ${x1 - 2} ${yTop + taper}
@@ -13325,44 +13323,24 @@ function AnimatedHighlight({ bbox, action }) {
13325
13323
  "feTurbulence",
13326
13324
  {
13327
13325
  type: "fractalNoise",
13328
- baseFrequency: "1.6",
13326
+ baseFrequency: "1.8",
13329
13327
  numOctaves: "1",
13330
13328
  seed: 3,
13331
13329
  result: "noise"
13332
13330
  }
13333
13331
  ),
13334
- /* @__PURE__ */ jsx44("feDisplacementMap", { in: "SourceGraphic", in2: "noise", scale: 1.4 })
13332
+ /* @__PURE__ */ jsx44("feDisplacementMap", { in: "SourceGraphic", in2: "noise", scale: 1 })
13335
13333
  ] }) }),
13336
- /* @__PURE__ */ jsxs37(
13337
- motion4.g,
13334
+ /* @__PURE__ */ jsx44(
13335
+ motion4.path,
13338
13336
  {
13337
+ d: pathD,
13338
+ fill,
13339
13339
  initial: { clipPath: `inset(0 100% 0 0)` },
13340
13340
  animate: { clipPath: `inset(0 0% 0 0)` },
13341
13341
  exit: { opacity: 0 },
13342
- transition: { duration, ease: EASE_OUT_EXPO },
13343
- children: [
13344
- /* @__PURE__ */ jsx44(
13345
- "path",
13346
- {
13347
- d: pathD,
13348
- fill,
13349
- opacity: 0.85,
13350
- filter: `url(#${filterId})`
13351
- }
13352
- ),
13353
- /* @__PURE__ */ jsx44(
13354
- "rect",
13355
- {
13356
- x: x1 - 1,
13357
- y: y1 - bleed * 0.4,
13358
- width: x2 - x1 + 2,
13359
- height: height - bleed * 0.8,
13360
- fill: inner,
13361
- opacity: 0.5,
13362
- filter: `url(#${filterId})`
13363
- }
13364
- )
13365
- ]
13342
+ filter: `url(#${filterId})`,
13343
+ transition: { duration, ease: EASE_OUT_EXPO }
13366
13344
  }
13367
13345
  )
13368
13346
  ]
@@ -14925,7 +14903,12 @@ var StoryboardStepSchema = z.object({
14925
14903
  });
14926
14904
  var StoryboardSchema = z.object({
14927
14905
  version: z.literal(1),
14928
- reasoning: z.string().max(500).default(""),
14906
+ // `reasoning` was required in 0.4.x as a model-generated explanation used
14907
+ // by DebugLog. It carries no visual effect and costs 50–150 output tokens
14908
+ // per call, so from 0.5.1 it's optional (default empty). Consumers who
14909
+ // still send it (from cached prompts or older directors) keep working —
14910
+ // the field is still accepted, just not required.
14911
+ reasoning: z.string().max(500).optional().default(""),
14929
14912
  steps: z.array(StoryboardStepSchema).min(1).max(4)
14930
14913
  });
14931
14914
  function storyboardJsonSchema(opts = {}) {
@@ -15040,7 +15023,10 @@ function storyboardJsonSchema(opts = {}) {
15040
15023
  return {
15041
15024
  type: "object",
15042
15025
  additionalProperties: false,
15043
- required: ["version", "reasoning", "steps"],
15026
+ // `reasoning` intentionally omitted from `required` the field is still
15027
+ // accepted when present but the model doesn't need to generate it,
15028
+ // which saves 50–150 output tokens per call. See zod schema above.
15029
+ required: ["version", "steps"],
15044
15030
  properties: {
15045
15031
  version: { type: "integer", enum: [1] },
15046
15032
  reasoning: { type: "string" },
@@ -15079,7 +15065,6 @@ Anchoring rules:
15079
15065
  Output ONLY this JSON, nothing else:
15080
15066
  {
15081
15067
  "version": 1,
15082
- "reasoning": "<which block(s) you picked, which intent you used, and why \u2014 name the block_id>",
15083
15068
  "steps": [ { "at_ms": <int>, "duration_ms": <int>, "action": <action> }, ... ]
15084
15069
  }
15085
15070
 
@@ -15116,7 +15101,6 @@ When narration fits one of these patterns, emit the corresponding storyboard sha
15116
15101
  Shape: spotlight the term + underline it + drop a label tag. No camera move if the block is already on-screen.
15117
15102
  {
15118
15103
  "version": 1,
15119
- "reasoning": "define recipe: spotlighting and underlining the term, labeling as 'definition'",
15120
15104
  "steps": [
15121
15105
  { "at_ms":0, "duration_ms":700, "action": { "type":"spotlight", "target_block":"p1_para0", "dim_opacity":0.6, "feather_px":40, "shape":"rounded" } },
15122
15106
  { "at_ms":200, "duration_ms":800, "action": { "type":"underline", "target_block":"p1_para0", "color":"#FBBF24", "style":"sketch", "draw_duration_ms":700 } },
@@ -15128,7 +15112,6 @@ Shape: spotlight the term + underline it + drop a label tag. No camera move if t
15128
15112
  Shape: gentle camera move + callout arrow from caption to figure + pulse the figure.
15129
15113
  {
15130
15114
  "version": 1,
15131
- "reasoning": "point_out recipe: drawing attention from caption p1_cap1 to figure p1_fig0",
15132
15115
  "steps": [
15133
15116
  { "at_ms":0, "duration_ms":600, "action": { "type":"camera", "target_block":"p1_fig0", "scale":1.3, "padding":80, "easing":"ease-out" } },
15134
15117
  { "at_ms":400, "duration_ms":900, "action": { "type":"callout", "from_block":"p1_cap1", "to_block":"p1_fig0", "label":"see here", "curve":"curved" } },
@@ -15140,7 +15123,6 @@ Shape: gentle camera move + callout arrow from caption to figure + pulse the fig
15140
15123
  Shape: box A + box B + callout between them with a relational label.
15141
15124
  {
15142
15125
  "version": 1,
15143
- "reasoning": "compare recipe: framing fibrous vs synovial joints",
15144
15126
  "steps": [
15145
15127
  { "at_ms":0, "duration_ms":600, "action": { "type":"box", "target_block":"p1_list5", "color":"#3B82F6", "style":"solid" } },
15146
15128
  { "at_ms":300, "duration_ms":600, "action": { "type":"box", "target_block":"p1_list12", "color":"#F472B6", "style":"solid" } },
@@ -15152,7 +15134,6 @@ Shape: box A + box B + callout between them with a relational label.
15152
15134
  Shape: highlight + pulse. Fast, punchy, no camera.
15153
15135
  {
15154
15136
  "version": 1,
15155
- "reasoning": "emphasize recipe: highlighting key keyword and pulsing for stress",
15156
15137
  "steps": [
15157
15138
  { "at_ms":0, "duration_ms":500, "action": { "type":"highlight", "target_block":"p1_list0", "color":"rgba(250,204,21,0.35)", "draw_duration_ms":450 } },
15158
15139
  { "at_ms":350, "duration_ms":800, "action": { "type":"pulse", "target_block":"p1_list0", "count":2, "intensity":"strong" } }
@@ -15459,9 +15440,10 @@ function enforceOverlayPresence(sb) {
15459
15440
  if (!cameraStep || cameraStep.action.type !== "camera") return sb;
15460
15441
  const target = cameraStep.action.target_block;
15461
15442
  if (!target) return sb;
15443
+ const prefix = sb.reasoning ? `${sb.reasoning} ` : "";
15462
15444
  return {
15463
15445
  ...sb,
15464
- reasoning: `${sb.reasoning} [auto-appended pulse: camera-only storyboards are forbidden]`,
15446
+ reasoning: `${prefix}[auto-appended pulse: camera-only storyboards are forbidden]`,
15465
15447
  steps: [
15466
15448
  ...sb.steps,
15467
15449
  {
@@ -15853,6 +15835,7 @@ function TutorModeContainer({
15853
15835
  backgroundColor = "#ffffff",
15854
15836
  loadingComponent,
15855
15837
  onPageChange,
15838
+ storyboardProvider,
15856
15839
  className
15857
15840
  }) {
15858
15841
  const containerRef = useRef27(null);
@@ -15931,7 +15914,7 @@ function TutorModeContainer({
15931
15914
  const debounceRef = useRef27(null);
15932
15915
  const lastChunkRef = useRef27(null);
15933
15916
  useEffect28(() => {
15934
- if (!llm) return;
15917
+ if (!storyboardProvider && !llm) return;
15935
15918
  if (!currentChunk || currentChunk === lastChunkRef.current) return;
15936
15919
  if (debounceRef.current) clearTimeout(debounceRef.current);
15937
15920
  debounceRef.current = setTimeout(async () => {
@@ -15952,6 +15935,75 @@ function TutorModeContainer({
15952
15935
  });
15953
15936
  abortRef.current?.abort();
15954
15937
  abortRef.current = new AbortController();
15938
+ if (storyboardProvider) {
15939
+ narrationStore.getState().setLlmStatus("in-flight");
15940
+ narrationStore.getState().appendDebugEvent({
15941
+ kind: "llm-request",
15942
+ summary: `provider (page ${pageNumber}, ${page2.blocks.length} blocks)`,
15943
+ payload: {
15944
+ via: "storyboardProvider",
15945
+ pageNumber,
15946
+ blockCount: page2.blocks.length
15947
+ }
15948
+ });
15949
+ try {
15950
+ const raw = await storyboardProvider({
15951
+ chunk,
15952
+ pageNumber,
15953
+ page: page2,
15954
+ history: narrationStore.getState().chunkHistory,
15955
+ signal: abortRef.current.signal
15956
+ });
15957
+ if (!raw) {
15958
+ narrationStore.getState().setLlmStatus("idle");
15959
+ narrationStore.getState().appendDebugEvent({
15960
+ kind: "note",
15961
+ summary: "provider returned null \u2014 no storyboard for this chunk"
15962
+ });
15963
+ return;
15964
+ }
15965
+ const parsed = StoryboardSchema.safeParse(raw);
15966
+ if (!parsed.success) {
15967
+ narrationStore.getState().setLlmStatus(
15968
+ "failed",
15969
+ parsed.error.message
15970
+ );
15971
+ narrationStore.getState().appendDebugEvent({
15972
+ kind: "llm-error",
15973
+ summary: `provider storyboard rejected by schema: ${parsed.error.issues[0]?.message ?? "unknown"}`,
15974
+ payload: { raw, error: parsed.error.message }
15975
+ });
15976
+ return;
15977
+ }
15978
+ const storyboard = parsed.data;
15979
+ narrationStore.getState().setLlmStatus("idle");
15980
+ narrationStore.getState().appendDebugEvent({
15981
+ kind: "llm-response",
15982
+ summary: summariseStoryboard(storyboard),
15983
+ payload: { via: "storyboardProvider", storyboard }
15984
+ });
15985
+ engineRef.current?.execute(storyboard);
15986
+ narrationStore.getState().appendDebugEvent({
15987
+ kind: "storyboard-execute",
15988
+ summary: `engine executing ${storyboard.steps.length} steps`,
15989
+ payload: storyboard.steps.map((s) => ({
15990
+ at_ms: s.at_ms,
15991
+ type: s.action.type,
15992
+ target: "target_block" in s.action ? s.action.target_block : void 0
15993
+ }))
15994
+ });
15995
+ } catch (e) {
15996
+ if (e.name === "AbortError") return;
15997
+ narrationStore.getState().setLlmStatus("failed", e.message);
15998
+ narrationStore.getState().appendDebugEvent({
15999
+ kind: "llm-error",
16000
+ summary: `provider threw: ${e.message.slice(0, 80)}`,
16001
+ payload: e
16002
+ });
16003
+ }
16004
+ return;
16005
+ }
16006
+ if (!llm) return;
15955
16007
  narrationStore.getState().setLlmStatus("in-flight");
15956
16008
  narrationStore.getState().appendDebugEvent({
15957
16009
  kind: "llm-request",
@@ -15973,7 +16025,7 @@ function TutorModeContainer({
15973
16025
  narrationStore.getState().setLlmStatus("idle");
15974
16026
  narrationStore.getState().appendDebugEvent({
15975
16027
  kind: "llm-response",
15976
- summary: `storyboard \u2713 ${result.storyboard.steps.length} steps \u2014 ${result.storyboard.reasoning.slice(0, 60)}`,
16028
+ summary: summariseStoryboard(result.storyboard),
15977
16029
  payload: { raw: result.raw, storyboard: result.storyboard }
15978
16030
  });
15979
16031
  engineRef.current?.execute(result.storyboard);
@@ -16016,7 +16068,16 @@ function TutorModeContainer({
16016
16068
  return () => {
16017
16069
  if (debounceRef.current) clearTimeout(debounceRef.current);
16018
16070
  };
16019
- }, [currentChunk, llm, index, pageNumber, narrationStore, embeddingProvider, llmTimeoutMs]);
16071
+ }, [
16072
+ currentChunk,
16073
+ llm,
16074
+ storyboardProvider,
16075
+ index,
16076
+ pageNumber,
16077
+ narrationStore,
16078
+ embeddingProvider,
16079
+ llmTimeoutMs
16080
+ ]);
16020
16081
  useEffect28(() => {
16021
16082
  if (!currentChunk) return;
16022
16083
  const t = setTimeout(() => {
@@ -16206,6 +16267,15 @@ function TutorLoadingState({
16206
16267
  }
16207
16268
  );
16208
16269
  }
16270
+ function summariseStoryboard(sb) {
16271
+ const stepCount = sb.steps.length;
16272
+ const trimmedReasoning = (sb.reasoning ?? "").trim();
16273
+ if (trimmedReasoning) {
16274
+ return `storyboard \u2713 ${stepCount} steps \u2014 ${trimmedReasoning.slice(0, 60)}`;
16275
+ }
16276
+ const kinds = sb.steps.map((s) => s.action.type).join(" \u2192 ");
16277
+ return `storyboard \u2713 ${stepCount} steps \u2014 ${kinds}`;
16278
+ }
16209
16279
 
16210
16280
  // src/director/transformers-embedding.ts
16211
16281
  var loaded = null;