npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@myadbox/nebula-template-utils

v0.4.49

Published

Template-related types and utilities for use in Sesimi apps and templates.

Downloads

2,968

Readme

Nebula Template Utils

Template-related utilities for use in Nebula and Exoplanet repos.

Table of contents

Introducing Nebula Template Utils

Nebula Template Utils provides a set of tools that bridge the divide between the Exoplanet repository and the Nebula repository. Many of these tools are used in both repos and provide consistency and interoperability between the two.

Much of this README pertains to users of Exoplanet repo, but there are many more features yet to be better documented.

About size preset categories

In order for the Sesimi app to know how to display a template’s preview to a user, we need to have set at least one size preset in the template config’s sizes array.

Size preset categories—such as newspaper, bannerAd and social—contain a structured (and growing) set of sizes from which we can compile a suitable list and add it to our template config’s sizes property. Ultimately, this list of presets (containing media dimensions, default formats and descriptive labels) is presented to a user as being well-supported choices for them to select and produce media from.

Categories list

Follow this link to view a flattened table detailing every current preset.

An example of preset category:

const exportDefaults = `print`

export const newspaper = {
  tallTabloid: {
    sizes: {
      fullPage: {
        label: `Tall tabloid full page`,
        width: 990,
        height: 1361,
        exportDefaults,
      },
      halfPage: {
        label: `Tall tabloid half page`,
        width: 990,
        height: 661,
        exportDefaults,
      },
    },
  },

  compactTabloid: {
    sizes: {
      fullPage: {
        label: `Compact tabloid full page`,
        width: 990,
        height: 1008,
        exportDefaults,
      },
    },
  },
}

Getting started

  1. Open /src//brands/[your template folder]/data/config.mjs
  2. Edit the config.mjs sizes and defaultSize objects to required sizes

Have a read of this snippet:

import {defineConfig, embedSizes, allSizes} from '@myadbox/nebula-template-utils'

export default defineConfig({
  sizes: embedSizes({
    support: {
      categories: [allSizes.newspaper, allSizes.paper.iso.a.a4, allSizes.paper.us.letter],
      specific: [allSizes.paper.iso.a.a4.sizes.portrait],
    },
  }),
  defaultSize: allSizes.newspaper.compactTabloid.sizes.fullPage.label,

  // the rest of config
  // fields: [...

})

The template default gives you a head start by importing what’s necessary, all you have to do is edit what’s there so let’s look at that step by step:

defineConfigrequired, do not edit


export default defineConfig({

This begins defining the object that becomes the entire JSON config data bundled with the template’s zip archive, and read by the Sesimi app to create the customised build form for the template. Wrapping the config object in this defineConfig function call enables VS Code to check your progress as you fill out the config object and alert you with red underlines when anything is incorrectly specified.

embedSizesrequired, do not edit


sizes: embedSizes({
  support: {

This embeds sizes available to the user. What is set here will show in their dropdown list.

categoriesoptional


    categories: [allSizes.newspaper, allSizes.paper.iso.a.a4, allSizes.paper.us.letter],

To display a full category for user selection, use categories.

E.g. allSizes.newspaper will display every available newspaper option.

This can be narrowed down if you only want to display a section of the whole category.

E.g. allSizes.newspaper.tallTabloid

Another example is isolating to A4, but both portrait and landscape options:

allSizes.paper.iso.a.a4

specificoptional


    specific: [allSizes.paper.iso.a.a4.sizes.portrait],

To display a specific size only, use specific. Note that while this is marked as "optional" there must be at least one size in a config’s sizes array. This specific option is often used to provide that when only one size is supported.

E.g. allSizes.paper.iso.a.a4.sizes.portrait will display A4 portrait only.

You can add as many specific sizes as needed, separated by a comma:

E.g. allSizes.social.facebook.main.sizes.linkPost, allSizes.social.instagram.main.sizes.post will display two social media size options for the user.

defaultSize — required


defaultSize: allSizes.paper.iso.a.a4.sizes.portrait.label, // NOTE: .label is important

To give the user an initial selected size, use defaultSize. This must be appended with .label to display the label in the select.

Modifying existing presets

You can optionally modify the format and/or quality of the embedded sizes. For example, if you want, say, the bannerAd category of sizes, but your template is animated, you'll want to override the default format (JPG) to be HTML. You can do this by passing the sizes you got via embedSizes into the modifySizes function, like so:

import {defineConfig, embedSizes, modifySizes, allSizes, Format} from '@myadbox/nebula-template-utils'

// for clarity, create a variable of the embedSizes result
const sizes = embedSizes({
  support: {
    categories: [allSizes.bannerAd],
  },
})

// pass in your sizes, along with an object that will override properties of each size
const modifiedSizes = modifySizes(sizes, {format: Format.Html})

export default defineConfig({
  // add the modified sizes to the config
  sizes: modifiedSizes,
  // ... config continues ...

Custom labels and sizes (TODO)

Contributing

To publish a new version, increment the version number in package.json and then run the following from the client workspace root:

yarn nx run @myadbox/nebula-template-utils:build && node ./tools/scripts/publish.mjs @myadbox/nebula-template-utils [ insert
your new version number here] latest