  A QCD factorization formalism was recently proposed for evaluating heavy
quarkonium production at large $p_T$ at collider energies. With systematically
calculated short-distance partonic hard parts and evolution kernels of
fragmentation functions (FFs), the predictive power of this factorization
approach relies on our knowledge of a large number of universal FFs at an input
factorization scale $\mu_0\gtrsim 2m_Q$ with heavy quark mass $m_Q$. With the
large heavy quark mass, the relative motion of the heavy quark pair inside a
heavy quarkonium is effectively non-relativistic. We evaluate these universal
input FFs using non-relativistic QCD (NRQCD) factorization, and express the
large number of FFs in terms of a few universal NRQCD long-distance matrix
elements (LDMEs) with perturbatively calculated coefficients. We derive
complete contributions to the single-parton FFs at both ${\cal O}(\alpha_s)$
and ${\cal O}(\alpha_s^2)$, and the heavy quark pair FFs at ${\cal
O}(\alpha_s)$. We present detailed derivation for all contributions involving
LDMEs of $S$-wave NRQCD $Q\bar{Q}$-states ($P$-wave contributions in a
companion paper). Our results bridge the gap between the QCD factorization
formalism and its phenomenological applications.
