| 235 | |
| 236 | // array of elements in, fitty instances out |
| 237 | function fittyCreate(elements, options) { |
| 238 | // set options object |
| 239 | const fittyOptions = Object.assign( |
| 240 | {}, |
| 241 | |
| 242 | // expand default options |
| 243 | defaultOptions, |
| 244 | |
| 245 | // override with custom options |
| 246 | options |
| 247 | ); |
| 248 | |
| 249 | // create fitties |
| 250 | const publicFitties = elements.map((element) => { |
| 251 | // create fitty instance |
| 252 | const f = Object.assign({}, fittyOptions, { |
| 253 | // internal options for this fitty |
| 254 | element, |
| 255 | active: true, |
| 256 | }); |
| 257 | |
| 258 | // initialise this fitty |
| 259 | init(f); |
| 260 | |
| 261 | // expose API |
| 262 | return { |
| 263 | element, |
| 264 | fit: fit(f, DrawState.DIRTY), |
| 265 | unfreeze: subscribe(f), |
| 266 | freeze: unsubscribe(f), |
| 267 | unsubscribe: destroy(f), |
| 268 | }; |
| 269 | }); |
| 270 | |
| 271 | // call redraw on newly initiated fitties |
| 272 | requestRedraw(); |
| 273 | |
| 274 | // expose fitties |
| 275 | return publicFitties; |
| 276 | } |
| 277 | |
| 278 | // fitty creation function |
| 279 | function fitty(target, options = {}) { |