PaperScript
Static Methods
Compiles PaperScript code into JavaScript code.
- options.url: String — the url of the source, for source-map generation
- options.source: String — the source to be used for the source- mapping, in case the code that’s passed in has already been mingled.
Options:
- code: String — the PaperScript code
- options: Object — the compilation options — optional
Parameters:
- Object — an object holding the compiled PaperScript translated into JavaScript code along with source-maps and other information.
Returns:
Compiles the PaperScript code into a compiled function and executes it. The compiled function receives all properties of the passed PaperScope as arguments, to emulate a global scope with unaffected performance. It also installs global view and tool handlers automatically on the respective objects.
- options.url: String — the url of the source, for source-map generation
- options.source: String — the source to be used for the source- mapping, in case the code that’s passed in has already been mingled.
- options.handlers: Array of Strings — the names of further global handlers to export next to
onFrame,onResizeand the tool’s handlers, for hosts that call them themselves - options.evaluate: Function — the evaluator for hosts that evaluate code their own way: called with the source of a function expression and
options.url, and returning the function, e.g. by evaluating the source as a script of that url - options.load: Function — the loader for static
importstatements, called with the specifier as written, theoptions.urlof the importing script, and the import attributes as an object, e.g.{ type: 'paperscript' }forimport x from 'm' with { type: 'paperscript' }, orundefinedwithout them, and returning the module’s exports, e.g. the result of executing it. Modules with ESexportstatements have their default export asdefaultand are marked with__esModule, soimport xreceives the default export, and for CommonJS-style exports the whole exports.import * as xreceives all exports, and for CommonJS-style exports, these asdefaulttoo. Dynamicimport(specifier)resolves to that namespace as a Promise, and its loader may return a Promise as well.import(specifier, options)passes onoptions.withas the attributes. The loader runs each module once and handles cycles. Parsingimportrequires a current Acorn asself.acornCode with top-levelawaitruns as an async function.execute()then returns a Promise of the exports, and installs the global handlers once it resolves. Parsing it requires a current Acorn asself.acorn.
Options:
- code: String — the PaperScript code
- scope: PaperScope — the scope for which the code is executed
- options: Object — the compilation options — optional
Parameters:
-
Object⟋Promise — the exports defined in the executed code, or with top-level
await, a Promise of them
Returns:
Loads, compiles and executes PaperScript code in the HTML document. Note that this method is executed automatically for all scripts in the document through a window load event. You can optionally call it earlier (e.g. from a DOM ready event), or you can mark scripts to be ignored by setting the attribute ignore="true" or data-paper-ignore="true", and call the PaperScript.load(script) method for each script separately when needed.
- script: HTMLScriptElement — the script to load. If none is provided, all scripts of the HTML document are iterated over and loaded — optional, default: null
Parameters:
-
PaperScope — the scope produced for the passed
script, orundefinedof multiple scripts area loaded