@ncukondo/slide-generation 0.1.0 → 0.2.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.d.ts CHANGED
@@ -147,6 +147,9 @@ declare const presentationSchema: z.ZodObject<{
147
147
  type PresentationMeta = z.infer<typeof metaSchema>;
148
148
  type ParsedSlide = z.infer<typeof slideSchema>;
149
149
  type ParsedPresentation = z.infer<typeof presentationSchema>;
150
+ interface ParseResultWithLines extends ParsedPresentation {
151
+ slideLines: number[];
152
+ }
150
153
  declare class ParseError extends Error {
151
154
  details?: unknown | undefined;
152
155
  constructor(message: string, details?: unknown | undefined);
@@ -158,6 +161,8 @@ declare class ValidationError extends Error {
158
161
  declare class Parser {
159
162
  parse(yamlContent: string): ParsedPresentation;
160
163
  parseFile(filePath: string): Promise<ParsedPresentation>;
164
+ parseWithLineInfo(yamlContent: string): ParseResultWithLines;
165
+ parseFileWithLineInfo(filePath: string): Promise<ParseResultWithLines>;
161
166
  }
162
167
 
163
168
  /**
@@ -501,13 +506,21 @@ interface IconOptions {
501
506
  color?: string;
502
507
  class?: string;
503
508
  }
509
+ /**
510
+ * Options for the IconResolver
511
+ */
512
+ interface IconResolverOptions {
513
+ /** Use CSS variables for theme colors (e.g., var(--theme-primary)) */
514
+ useThemeVariables?: boolean;
515
+ }
504
516
  /**
505
517
  * Icon Resolver - renders icons from various sources
506
518
  */
507
519
  declare class IconResolver {
508
520
  private registry;
509
521
  private nunjucksEnv;
510
- constructor(registry: IconRegistryLoader);
522
+ private options;
523
+ constructor(registry: IconRegistryLoader, options?: IconResolverOptions);
511
524
  /**
512
525
  * Render an icon by name or alias
513
526
  */
@@ -540,6 +553,10 @@ declare class IconResolver {
540
553
  * Build class name string
541
554
  */
542
555
  private buildClassName;
556
+ /**
557
+ * Resolve color value, supporting palette names and CSS variables
558
+ */
559
+ private resolveColor;
543
560
  }
544
561
 
545
562
  interface CSLAuthor {
@@ -994,6 +1011,6 @@ declare class Pipeline {
994
1011
  /**
995
1012
  * slide-generation - A CLI tool to generate Marp-compatible Markdown from YAML source files
996
1013
  */
997
- declare const VERSION = "0.1.0";
1014
+ declare const VERSION: string;
998
1015
 
999
1016
  export { type IconsHelper, type JsonSchema, type MetaContext, ParseError, type ParsedPresentation, type ParsedSlide, Parser, Pipeline, PipelineError, type PipelineOptions, type PipelineResult, type PresentationMeta, type RefsHelper, type RenderOptions, Renderer, type SlideContext, type TemplateContext, type TemplateDefinition, TemplateEngine, TemplateLoader, type TransformContext, TransformError, Transformer, VERSION, ValidationError, type ValidationResult, jsonSchemaToZod, presentationSchema, templateDefSchema, validateWithJsonSchema };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  // src/core/parser.ts
2
2
  import { z } from "zod";
3
- import { parse as parseYaml } from "yaml";
3
+ import { parse as parseYaml, parseDocument, isSeq, isMap, isNode, LineCounter } from "yaml";
4
4
  import { readFile } from "fs/promises";
5
5
  var referencesConfigSchema = z.object({
6
6
  enabled: z.boolean().default(true),
@@ -67,6 +67,50 @@ var Parser = class {
67
67
  }
68
68
  return this.parse(content);
69
69
  }
70
+ parseWithLineInfo(yamlContent) {
71
+ const lineCounter = new LineCounter();
72
+ const doc = parseDocument(yamlContent, { lineCounter });
73
+ if (doc.errors && doc.errors.length > 0) {
74
+ throw new ParseError("Failed to parse YAML", doc.errors);
75
+ }
76
+ const slideLines = [];
77
+ const contents = doc.contents;
78
+ if (isMap(contents)) {
79
+ const slidesNode = contents.get("slides", true);
80
+ if (isSeq(slidesNode)) {
81
+ for (const item of slidesNode.items) {
82
+ if (isNode(item) && item.range) {
83
+ const pos = lineCounter.linePos(item.range[0]);
84
+ slideLines.push(pos.line);
85
+ }
86
+ }
87
+ }
88
+ }
89
+ const rawData = doc.toJSON();
90
+ const result = presentationSchema.safeParse(rawData);
91
+ if (!result.success) {
92
+ throw new ValidationError(
93
+ "Schema validation failed",
94
+ result.error.format()
95
+ );
96
+ }
97
+ return {
98
+ ...result.data,
99
+ slideLines
100
+ };
101
+ }
102
+ async parseFileWithLineInfo(filePath) {
103
+ let content;
104
+ try {
105
+ content = await readFile(filePath, "utf-8");
106
+ } catch (error) {
107
+ if (error.code === "ENOENT") {
108
+ throw new ParseError(`File not found: ${filePath}`);
109
+ }
110
+ throw new ParseError(`Failed to read file: ${filePath}`, error);
111
+ }
112
+ return this.parseWithLineInfo(content);
113
+ }
70
114
  };
71
115
 
72
116
  // src/core/transformer.ts
@@ -665,13 +709,15 @@ import * as fs3 from "fs/promises";
665
709
  import * as path2 from "path";
666
710
  import nunjucks2 from "nunjucks";
667
711
  var IconResolver = class {
668
- constructor(registry) {
712
+ constructor(registry, options = {}) {
669
713
  this.registry = registry;
670
714
  this.nunjucksEnv = new nunjucks2.Environment(null, {
671
715
  autoescape: false
672
716
  });
717
+ this.options = options;
673
718
  }
674
719
  nunjucksEnv;
720
+ options;
675
721
  /**
676
722
  * Render an icon by name or alias
677
723
  */
@@ -690,7 +736,7 @@ var IconResolver = class {
690
736
  const defaults = this.registry.getDefaults();
691
737
  const mergedOptions = {
692
738
  size: options?.size ?? defaults.size,
693
- color: options?.color ?? defaults.color,
739
+ color: this.resolveColor(options?.color) ?? defaults.color,
694
740
  ...options?.class !== void 0 ? { class: options.class } : {}
695
741
  };
696
742
  switch (source.type) {
@@ -812,6 +858,22 @@ var IconResolver = class {
812
858
  }
813
859
  return classes.join(" ");
814
860
  }
861
+ /**
862
+ * Resolve color value, supporting palette names and CSS variables
863
+ */
864
+ resolveColor(color) {
865
+ if (!color) {
866
+ return void 0;
867
+ }
868
+ const paletteColor = this.registry.getColor(color);
869
+ if (paletteColor) {
870
+ if (this.options.useThemeVariables) {
871
+ return `var(--theme-${color})`;
872
+ }
873
+ return paletteColor;
874
+ }
875
+ return color;
876
+ }
815
877
  };
816
878
 
817
879
  // src/references/manager.ts
@@ -1448,7 +1510,7 @@ var Pipeline = class {
1448
1510
  };
1449
1511
 
1450
1512
  // src/index.ts
1451
- var VERSION = "0.1.0";
1513
+ var VERSION = "0.2.1";
1452
1514
  export {
1453
1515
  ParseError,
1454
1516
  Parser,