% Copyright 2026 Open-Guji (https://github.com/open-guji)
%
% Licensed under the Apache License, Version 2.0 (the "License");
% you may not use this file except in compliance with the License.
% You may obtain a copy of the License at
%
%     http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
% See the License for the specific language governing permissions and
% limitations under the License.

% luatex_cn.sty
% LuaTeX package for Chinese typesetting support
% Main wrapper package that loads sub-packages and exposes unified interface
%
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{luatex-cn}[2026/01/19 v0.1.1 Chinese typesetting support for LuaTeX]

% Load expl3 (LaTeX3 programming layer)
\RequirePackage{expl3}
\ExplSyntaxOn

% Check if LuaTeX is being used
\RequirePackage{ifluatex}
\ifluatex\else
  \PackageError{luatex-cn}{This package requires LuaTeX}{%
    Please compile your document with LuaLaTeX instead of pdfLaTeX or XeLaTeX.}
\fi

% ============================================================================
% Package Options
% ============================================================================
\bool_new:N \g_luatexcn_banxin_bool
\bool_new:N \g_luatexcn_traditional_bool
\bool_new:N \g_luatexcn_simplified_bool

% Default: simplified Chinese
\bool_set_true:N \g_luatexcn_simplified_bool

% Define package options
\DeclareOption{banxin}
  {
    \bool_set_true:N \g_luatexcn_banxin_bool
  }
\DeclareOption{traditional}
  {
    \bool_set_true:N \g_luatexcn_traditional_bool
    \bool_set_false:N \g_luatexcn_simplified_bool
  }
\DeclareOption{simplified}
  {
    \bool_set_true:N \g_luatexcn_simplified_bool
    \bool_set_false:N \g_luatexcn_traditional_bool
  }

\ProcessOptions\relax

% ============================================================================
% Load Sub-packages (from their respective directories)
% ============================================================================

% Core vertical typesetting engine (always loaded)
\RequirePackage{luatex-cn-vertical}

% Banxin (版心) features - optional
\bool_if:NT \g_luatexcn_banxin_bool
  {
    \RequirePackage{luatex-cn-banxin}
  }

% ============================================================================
% Interface Documentation
% ============================================================================
% This package exposes the following commands:
%
%   \Vertical[options]{content}     - Main vertical layout command (Alias: \竖排)
%   \TextBox[options]{content}      - Grid-based textbox (Alias: \文本框)
%   \Paragraph                      - Environment for grid paragraphs
%   \TextFlow{content}              - Interlinear notes (Alias: \文本流)
%   \Space[width]                   - Explicit spacing (Alias: \空格)
%
%   \cnvdebugon / \cnvdebugoff      - Debug toggle
%
% ============================================================================
% CJK Aliases and Support
% ============================================================================
\NewEnvironmentCopy{列表}{itemize}

% ============================================================================
% Interface Documentation
% ============================================================================
% From banxin (when loaded with [banxin] option):
%   \banxinSetup{options}           - Configure banxin settings
%   \setBookName{name}              - Set book name for banxin
%   \setChapterTitle{title}         - Set chapter title
%
%   Additional aliases: \夹注 (for \TextFlow)
% ============================================================================

% Version info (synchronized with VERSION file in project root)
\newcommand{\luatexcnversion}{0.1.1}

% Main package initialization
\PackageInfo{luatex_cn}{Chinese typesetting package v\luatexcnversion\space loaded}

\ExplSyntaxOff

\endinput
