Skip to content

Commit

Permalink
Rewrite to generalize mappings (fix #13) and global cache (fix #50)
Browse files Browse the repository at this point in the history
* Support mapping defined by `Map` or `WeakMap`
* All function mappings are now automatically dynamic;
  no need to wrap in a second layer of function.
* Can force old static behavior (for efficiency)
  via `svgtiler.static` wrapper, cached at `Mapping` level.
* Function mappings get `context` second argument in addition to `this`.
* `Context` object now shared throughout each drawing
  (so you could store extra drawing-specific data there).
* API change: `Context` no longer has `symbols`, `symbol`, `data`,
  `filename`, or `subname` attributes.  For the latter three,
  use `drawing.data`, `drawing.filename`, or `drawing.subname`.
* API change: No more `Symbol`, `StaticSymbol`, or `DynamicSymbol` class
  (in particular, there was a name conflict with JS's `Symbol`)
* API change: `Input` constructor supports direct loading of data
  (for easy manual creation) or immediate parsing of file data,
  as well as option setting.  This will help with #34.
* New `Tile` class represents an expanded (and possibly parsed)
  tile `<symbol>` (roughly what `Symbol` was before).
* Tile caching/deduplication now within the renderer, not by `Symbol`
  (fix #50), enabling re-use when multiple symbols expand to the same SVG.
* Fix: Don't fill in `<image>` `width`/`height` when both already set.
* Fix: Use `hasOwnProperty` and `Set`s to avoid accidentally matching
  e.g. `toString`.
  • Loading branch information
edemaine committed Aug 13, 2022
1 parent 25caba5 commit bfdc132
Show file tree
Hide file tree
Showing 2 changed files with 298 additions and 266 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ In any case, `mapping` should be an expression evaluating to either
2. a *function* in one argument, a symbol name (string).
(This feature allows you to parse symbol names how you want; or check an
object for a matching key but use a default value otherwise; etc.).
xxx Map

The object or function should map a symbol name to either

Expand All @@ -197,6 +198,8 @@ The object or function should map a symbol name to either
4. a filename with `.png`, `.jpg`, `.jpeg`, or `.gif` extension containing an
image (which will get [processed](#image-processing) as an `<image>`), or
5. a function returning one of the above.
xxx undefined means 'symbol not defined by this mapping, go to next mapping'
xxx empty string means 'blank 0x0 symbol'

In the last case, the function is called *for each occurrence of the symbol*,
and has `this` bound to a manufactured `Context` object, giving you access to
Expand Down
Loading

0 comments on commit bfdc132

Please sign in to comment.