2023-04-16 17:18:02 -04:00
|
|
|
import { Pattern } from './pattern/index.mjs'
|
2022-09-18 15:11:10 +02:00
|
|
|
import { __loadDesignDefaults } from './config.mjs'
|
2022-08-13 14:27:39 +02:00
|
|
|
|
2022-09-18 15:11:10 +02:00
|
|
|
//////////////////////////////////////////////
|
|
|
|
// CONSTRUCTOR //
|
|
|
|
//////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a Pattern constructor (it's a super-constructor)
|
|
|
|
*
|
|
|
|
* @constructor
|
2022-09-24 12:44:41 +02:00
|
|
|
* @param {object} designConfig - The design configuration
|
2022-09-18 15:11:10 +02:00
|
|
|
* @return {function} pattern - The pattern constructor
|
2022-08-07 17:29:33 +02:00
|
|
|
*/
|
2022-09-24 12:44:41 +02:00
|
|
|
export function Design(designConfig) {
|
|
|
|
// Initialize designConfig with defaults
|
|
|
|
designConfig = { ...__loadDesignDefaults(), ...designConfig }
|
2022-08-13 14:27:39 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
// Create the pattern constructor
|
2022-09-17 10:24:13 +02:00
|
|
|
const pattern = function (...sets) {
|
2022-09-24 12:44:41 +02:00
|
|
|
// Pass the designConfig
|
|
|
|
Pattern.call(this, designConfig)
|
2022-08-07 17:29:33 +02:00
|
|
|
|
2022-09-09 20:20:38 +02:00
|
|
|
// Pass the pattern settings
|
2022-09-17 10:24:13 +02:00
|
|
|
return this.__applySettings(sets)
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2019-02-16 07:28:56 +01:00
|
|
|
|
|
|
|
// Set up inheritance
|
2019-08-03 15:03:33 +02:00
|
|
|
pattern.prototype = Object.create(Pattern.prototype)
|
|
|
|
pattern.prototype.constructor = pattern
|
2019-02-16 07:28:56 +01:00
|
|
|
|
2022-09-25 09:18:41 +02:00
|
|
|
// Make design & pattern config available without instantiating a pattern
|
2022-09-24 12:44:41 +02:00
|
|
|
pattern.designConfig = designConfig
|
2022-09-25 09:18:41 +02:00
|
|
|
pattern.patternConfig = new pattern().getConfig()
|
2019-09-21 19:42:53 +02:00
|
|
|
|
2019-08-03 15:03:33 +02:00
|
|
|
return pattern
|
2019-02-16 07:28:56 +01:00
|
|
|
}
|