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

minizinc-embedded

v3.0.2

Published

Embedded MiniZinc ================= [![License: MIT][mit-image]][mit-url] [![NPM version][npm-image]][npm-url]

Downloads

38

Readme

Embedded MiniZinc

License: MIT NPM version

This is a utility project to create simple embedded MiniZinc snippets that can be solved.

Basic Example

<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" href="https://unpkg.com/minizinc-embedded/build/minizinc.css">
  <script src="https://unpkg.com/minizinc-embedded/build/minizinc.js" data-init></script>
</head>
<body>
  <pre class="minizinc-embedding">
    int: n = 4; % The number of queens.

    array [1..n] of var 1..n: q;

    include "alldifferent.mzn";

    constraint alldifferent(q);
    constraint alldifferent(i in 1..n)(q[i] + i);
    constraint alldifferent(i in 1..n)(q[i] - i);

    solve satisfy;
  </pre>
</body>
</html>

will wrap the given embedding and add a Solve button to the top right.

Usage

Include in your website:

<link rel="stylesheet" href="https://unpkg.com/minizinc-embedded/build/minizinc.css">
<script src="https://unpkg.com/minizinc-embedded/build/minizinc.js"></script>

To initialize the embedding one can run the following JavaScript or add some data- attributes or CSS classes to the script tag.

MiniZincEmbedded.init({
  //root options go here
});

has the same effect as:

<script src="https://unpkg.com/minizinc-embedded/build/minizinc.js" data-init></script>

Options

The script tag as well as each individual embedding provide a range of customization options. See ./src/options.ts for a whole list of options. Most options can be defined using a CSS class or a data- attribute. For example:

<div class="minizinc-embedded-option-no-stats" data-no-stats></div>

are aquivalent. Moreover, all options on an embedding element supersedes the script tag options.

An important root options (only available in the script tag or during .init({...})) is selector. This option specifies the CSS selector to use for determing the set of embeddings. By default it is set to .minizinc-embedding matching all elements having the .minizinc-embedding class.

Model and Data Definition

In order to determine which part of the snippet is the model and which is the data file the following strategy is used: any element within the embedding matching the CSS selector [data-type=mzn], [type="text/x-minizinc"], .minizinc-embedded-model is considered the element containg the model. The model itself is retrieved using the .textContent property. The data file is similarly determined based on the CSS selector [data-type=dzn], [type="text/x-dzn"], .minizinc-embedded-data. As an alternative one can specify the global selector as part of the data option. In addition, the special data-data="next" syntax is supported. In case no model element can be found the embedding root element itself is used as input.

Example

<div class="minizinc-embedding">
  <pre data-type="mzn">
    int: n; % The number of queens.

    array [1..n] of var 1..n: q;

    include "alldifferent.mzn";

    constraint alldifferent(q);
    constraint alldifferent(i in 1..n)(q[i] + i);
    constraint alldifferent(i in 1..n)(q[i] - i);

    solve satisfy;
  </pre>
  <pre data-type="dzn">
    n = 4;
  </pre>
</div>

Advanced Usage

The globally exported MiniZincEmbedded object has the same interface as any other IMiniZinc object, thus allowing to solve simple models directly.

MiniZincEmbedded.solve(`int i = 4;`).then((result) => {
  console.log(result);
});
MiniZincEmbedded.solveRaw(`int i = 4;`).then((output) => {
  console.log(output);
});

Development Environment

Installation

git clone https://gitlab.com/minizinc/minizinc-webide.git
cd minizinc
npm install

Build distribution packages

npm run dist